Someone help! I would like to get a script together that will require a user to input information such as name, address, phone..etc and store it as a cookie so that when they return to the page, the information is prefilled for the next time that they use the form. I know that my naming convention is wrong, but I don't understand why because I am new at this. Please look this over and explain to me how to fix it in simple terms.
Thanks!
<SCRIPT LANGUAGE="JavaScript"><!--
function Get_Cookie(name) {
var start = document.cookie.indexOf(name+"="
var len = start+name.length+1;
if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
if (start == -1) return null;
var end = document.cookie.indexOf(";",len);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(len,end));
}
function Set_Cookie(name,value,expires,path,domain,secure) {
document.cookie = name + "=" +escape(value) +
( (expires) ? ";expires=" + expires.toGMTString() : "" +
( (path) ? ";path=" + path : "" +
( (domain) ? ";domain=" + domain : "" +
( (secure) ? ";secure" : ""
}
function setupForm() {
if (userProfile) getValues(userProfile);
}
function getValues(string) {
getValue(string,"FirstLastname", document.pts01reg.FirstLastname, "text"
getValue(string,"PhoneNumber", document.pts01reg.PhoneNumber, "text"
getValue(string,"EmailAddress", document.pts01reg.EmailAddress, "text"
getValue(string,"Location", document.pts01reg.Location, "text"
getValue(string,"Program_Title", document.pts01reg.Program_Title. "select"
for (var i=0;i<7+1;i++)
getValue(string,"i"+i, eval("document.pts01reg.i"+i), "checkbox"
}
function replace(string,text,by) {
// Replaces text with by in string
var i = string.indexOf(text);
var newstr = '';
if ((!i) || (i == -1)) return string;
newstr += string.substring(0,i) + by;
if (i+text.length < string.length)
newstr += replace(string.substring(i+text.length,string.length),text,by);
return newstr;
}
function onCheck(string) { if (string == "on" return true; return false; }
function getValue(string,elementName,object,elementType) {
// gets value of elementName from string and populates object of elementType
var startPos = string.indexOf(elementName + "="
if (startPos > -1) {
startPos = startPos + elementName.length + 1;
var endPos = string.indexOf("&",startPos);
if (endPos == -1) endPos = string.length;
var elementValue = unescape(string.substring(startPos,endPos));
if (elementType == "text" object.value = elementValue;
if (elementType == "password" object.value = elementValue;
if (elementType == "select" object.selectedIndex = elementValue;
if (elementType == "checkbox" object.checked = onCheck(elementValue);
if (elementType == "radio" object[elementValue].checked = true;
}
}
//--></SCRIPT>
</head>
<BODY onLoad="setupForm()" background="lt%20background.gif" bgproperties="fixed">
<SCRIPT LANGUAGE="JavaScript"><!--
var today = new Date();
var expires = new Date(today.getTime() + (365 * 24 * 60 * 60 * 1000));
var searchString = replace(self.location.search.substring(1),"+"," "
if (searchString.length > 0) Set_Cookie("userProfile",searchString,expires);
var userProfile = Get_Cookie("userProfile"
if (!userProfile) {
document.write('<P>Welcome,<P>According to your records ');
document.write('you have not set your user profile:');
}
else {
document.write('<P>Welcome back,<P>According to your records ');
document.write('the following settings are held in your profile:');
}
//--></SCRIPT> [sig][/sig]
Thanks!
<SCRIPT LANGUAGE="JavaScript"><!--
function Get_Cookie(name) {
var start = document.cookie.indexOf(name+"="
var len = start+name.length+1;
if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
if (start == -1) return null;
var end = document.cookie.indexOf(";",len);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(len,end));
}
function Set_Cookie(name,value,expires,path,domain,secure) {
document.cookie = name + "=" +escape(value) +
( (expires) ? ";expires=" + expires.toGMTString() : "" +
( (path) ? ";path=" + path : "" +
( (domain) ? ";domain=" + domain : "" +
( (secure) ? ";secure" : ""
}
function setupForm() {
if (userProfile) getValues(userProfile);
}
function getValues(string) {
getValue(string,"FirstLastname", document.pts01reg.FirstLastname, "text"
getValue(string,"PhoneNumber", document.pts01reg.PhoneNumber, "text"
getValue(string,"EmailAddress", document.pts01reg.EmailAddress, "text"
getValue(string,"Location", document.pts01reg.Location, "text"
getValue(string,"Program_Title", document.pts01reg.Program_Title. "select"
for (var i=0;i<7+1;i++)
getValue(string,"i"+i, eval("document.pts01reg.i"+i), "checkbox"
}
function replace(string,text,by) {
// Replaces text with by in string
var i = string.indexOf(text);
var newstr = '';
if ((!i) || (i == -1)) return string;
newstr += string.substring(0,i) + by;
if (i+text.length < string.length)
newstr += replace(string.substring(i+text.length,string.length),text,by);
return newstr;
}
function onCheck(string) { if (string == "on" return true; return false; }
function getValue(string,elementName,object,elementType) {
// gets value of elementName from string and populates object of elementType
var startPos = string.indexOf(elementName + "="
if (startPos > -1) {
startPos = startPos + elementName.length + 1;
var endPos = string.indexOf("&",startPos);
if (endPos == -1) endPos = string.length;
var elementValue = unescape(string.substring(startPos,endPos));
if (elementType == "text" object.value = elementValue;
if (elementType == "password" object.value = elementValue;
if (elementType == "select" object.selectedIndex = elementValue;
if (elementType == "checkbox" object.checked = onCheck(elementValue);
if (elementType == "radio" object[elementValue].checked = true;
}
}
//--></SCRIPT>
</head>
<BODY onLoad="setupForm()" background="lt%20background.gif" bgproperties="fixed">
<SCRIPT LANGUAGE="JavaScript"><!--
var today = new Date();
var expires = new Date(today.getTime() + (365 * 24 * 60 * 60 * 1000));
var searchString = replace(self.location.search.substring(1),"+"," "
if (searchString.length > 0) Set_Cookie("userProfile",searchString,expires);
var userProfile = Get_Cookie("userProfile"
if (!userProfile) {
document.write('<P>Welcome,<P>According to your records ');
document.write('you have not set your user profile:');
}
else {
document.write('<P>Welcome back,<P>According to your records ');
document.write('the following settings are held in your profile:');
}
//--></SCRIPT> [sig][/sig]