Well, let me post the Javascript part of my code, maybe that can help me explain what I need
I basically need to replace the arrays with cookies. So when the user clicks add, the info is stored in a cookie, and when the user clicks search, the info is retrieved from the cookie.
Code:
var entryArray = new Array();
function addEntry( )
{
//Variables from the form
var firstNameElement = document.myform.firstname;
var lastNameElement = document.myform.lastname;
var emailElement = document.myform.email;
var firstname = firstNameElement.value;
var lastname = lastNameElement.value;
var email = emailElement.value;
//Validate values to make sure they aren't blank
if (firstname == '')
{
alert("Please enter a First Name");
return;
}
if (lastname == '')
{
alert("Please enter a Last Name");
return;
}
if (email == '')
{
alert("Please enter an Email Address");
return;
}
//Validate names, convert to proper case, remove blanks
firstname = firstname.replace(/ /, "");
var firstname_1 = firstname.substr(0, 1);
var firstname_1 = firstname_1.toUpperCase( );
var firstname_rest = firstname.substr(1);
var firstname_rest = firstname_rest.toLowerCase( );
firstname = firstname_1 + firstname_rest;
//alert(firstname);
if(firstname.search(/[^a-zA-Z']/g) != -1)
{
alert("Only valid characters are letters and apostrophes");
firstNameElement.focus( );
return;
}
lastname = lastname.replace(/ /, "");
var lastname_1 = lastname.substr(0, 1);
var lastname_1 = lastname_1.toUpperCase( );
var lastname_rest = lastname.substr(1);
var lastname_rest = lastname_rest.toLowerCase( );
lastname = lastname_1 + lastname_rest;
if(lastname.search(/[^a-zA-Z']/g) != -1)
{
alert("Only valid characters are letters and apostrophes");
lastNameElement.focus( );
return;
}
//Validate email, convert to lower case
email = email.replace(/ /, "");
email = email.toLowerCase( );
var position = email.indexOf('@') ;
if(position == -1 )
{
alert("Email must have an @ in it");
emailElement.focus( );
return;
}
else
{
var position2 = email.indexOf('@', position + 1) ;
if(position2 != -1 )
{
alert("You have more than one @ in the email address");
emailElement.focus( );
return;
}
}
if(email.search(/[^a-z\d-_.@]/g) != -1)
{
alert("Only valid characters are letters, numbers, underscore, period, hyphen, and @ sign");
emailElement.focus( );
return;
}
if(email.search(/^[a-z]/) == -1)
{
alert("Email must begin with a letter");
emailElement.focus( );
return;
}
//Add to the array
var elementString = firstname + "," + lastname + "," + email;
var newIndex = entryArray.length; //find the position of the last element in the array
entryArray[newIndex] = elementString; //add element to the array
}
function searchEntry( )
{
var resultsElement = document.myform.results;
resultsElement.value = "";
var firstNameElement = document.myform.firstname;
var lastNameElement = document.myform.lastname;
var emailElement = document.myform.email;
var firstname = firstNameElement.value;
var lastname = lastNameElement.value;
var email = emailElement.value;
var resultString = "";
for (index in entryArray)
{
//split up element into array and individual elements
var myArray = entryArray[index].split(",");
var firstname_fromarray = myArray[0];
var lastname_fromarray = myArray[1];
var email_fromarray = myArray[2];
var fpattern = new RegExp("^" + firstname, "i");
var lpattern = new RegExp("^" + lastname, "i");
var epattern = new RegExp(email, "gi");
var matched_element = "N";
if (firstname != "")
{
if(fpattern.test(firstname_fromarray))
{
matched_element = "Y";
}
}
if (lastname != "")
{
if(lpattern.test(lastname_fromarray))
{
matched_element = "Y";
}
}
if (email != "")
{
if(epattern.test(email_fromarray))
{
matched_element = "Y";
}
}
if (matched_element == "Y")
{
resultString = resultString + firstname_fromarray + ", " + lastname_fromarray + ", " + email_fromarray + "\n";
}
}
resultsElement.value = resultString; //Set the text area with search mataches
}
Bookmarks