Click to See Complete Forum and Search --> : Cookies problem
klloyd
09-22-2003, 09:08 AM
Hi all. I'm having an issue with a script I am using to create a cookie to remember our customer's info so that they do not have to plug this info every time they fill out our forms. You do not need to submit the forms for the script to work, simply input data then leave the page and return. The url's using this script are at:
(please do not hit submit on the forms!)
http://www.wattscopy.com/services/meter.htm
http://www.wattscopy.com/services/service.htm
http://www.wattscopy.com/services/supplies.htm
The issue is in testing these pages is if you happen to fill out all 3 forms, suddenly the cookie stops filling some (not all) of the data in one of the other forms. I am not a cookie genius so please help!
Thanks to all who reply,
Kevin
Khalid Ali
09-22-2003, 01:03 PM
I this might have to do with the cookie size limit.
Traditionally cookie size was limited to 4k data,
which I Know is not true in the newer versions of NS6+ browsers they can handle more data then that,however,I know that untl recently(when I tested) IE6+ still does not store more data then 4 kilobytes.....
klloyd
09-22-2003, 01:37 PM
Is there anyway I could have a separate cookie for each page/form? I imagine it's possible but have no idea how to specify different cookies for different pages.
Khalid Ali
09-22-2003, 01:42 PM
You can do this,by naming each cookie for each form separately.which means a cookie for form1 may be named form1
and same will be for other forms
form2, form3 and so on.
klloyd
09-22-2003, 02:43 PM
If it's not too much trouble could you possibly point out where all in my script I can specify the cookie's name?
<script language="JavaScript">
<!--
var never = new Date()
never.setTime(never.getTime() + 2000*24*60*60*1000);
function SetCookie(name, value) {
var expString = "; expires=" + never.toGMTString();
document.cookie = name + "=" + escape(value) + expString;
}
function GetCookie(name) {
var result = null;
var myCookie = " " + document.cookie + ";";
var searchName = " " + name + "=";
var startOfCookie = myCookie.indexOf(searchName);
var endOfCookie;
if (startOfCookie != -1) {
startOfCookie += searchName.length;
endOfCookie = myCookie.indexOf(";", startOfCookie);
result = unescape(myCookie.substring(startOfCookie, endOfCookie));
}
return result;
}
use_cookies = "unsure";
function saveValue(element) {
if (document.images && use_cookies == "unsure") {
if ((element.type == "text")
|| (element.type == "password")
|| (element.type == "textarea")
|| (element.type == "radio")) {
val = element.value;
} else if (element.type.indexOf("select") != -1) {
val = "";
for(k=0;k<element.length;k++)
if (element.options[k].selected)
val += k+" ";
} else if (element.type == "checkbox") {
val = element.checked;
}
SetCookie("memory_"+element.form.name+"_"+element.name,val);
}
}
function storedValues() {
if (document.images) {
for (i=0;i<document.forms.length;i++) {
for (j=0;j<document.forms[i].elements.length; j++) {
cookie_name = "memory_"+document.forms[i].name+"_"
+document.forms[i].elements[j].name;
val = GetCookie(cookie_name);
if (val) {
if ((document.forms[i].elements[j].type == "text")
|| (document.forms[i].elements[j].type == "password")
|| (document.forms[i].elements[j].type == "textarea")) {
document.forms[i].elements[j].value = val;
} else if (document.forms[i].elements[j].type.indexOf("select") != -1) {
document.forms[i].elements[j].selectedIndex = -1;
while (((pos = val.indexOf(" ")) != -1) && (val.length > 1)) {
sel = parseInt(val.substring(0,pos));
val = val.substring(pos+1,val.length);
if (sel < document.forms[i].elements[j].length)
document.forms[i].elements[j].options[sel].selected = true;
}
} else if (document.forms[i].elements[j].type == "checkbox") {
document.forms[i].elements[j].checked = val;
} else if (document.forms[i].elements[j].type == "radio") {
if (document.forms[i].elements[j].value == val)
document.forms[i].elements[j].checked = true;
}
}
}
}
}
}
window.onload = storedValues;
// -->
</script>
Khalid Ali
09-22-2003, 05:55 PM
Look at this part in your code
SetCookie(name, value) {
in the function first parameter is
name
you will have to locatre where you are setting the cookie from and in that you will have the cookie name string as parameter.
change this accordoing to form name
you will eed to make changes in set and get cookie methods
klloyd
09-23-2003, 12:04 PM
I found and changed cookie_name="memory_" to cookie_name="meter" but it just changed the string stored in the cookie txt file. I guess what I really need is to have each page create a different cookie with a different file name as to avoid the cookie size problem. I'm pretty sure this is the problem because it seemed to only lose info on the first page out of the 3 visited after returning to the first page and never lost the same amount of info each time I tested it. That seems consistent with a file size issue to me. Can a separate cookie file per page be done?