I found that the recently highlighted JavaScript Source: Cookies : Save and Restore Form Cookies works very nicely, after a couple of things are changed.
1)
Change var formname = frm.id;
To var formname = frm.name;
– this occurs in both saveSelections() and loadSelections()
2)
add to the saveSelections()
if (fieldType == “hidden”) {
//alert(frm.elements[e].length);
string = string + frm.elements[e].value + “|
//alert(“text”);
}
3)
add to the saveSelections()
if (fieldType == “hidden”) frm.elements[e].value = fieldValue;
It would also be useful to add the instructions on how to implement it:
Change <BODY>
To <BODY onunload=”saveSelections(document.forms[0])”>
and
Change </FORM>
TO </FORM><SCRIPT language=JavaScript type=””>loadSelections(document.forms[0]);</SCRIPT>
You also need to make sure you already have some functions called
getCookie(name)
and
setCookie(name, value, expires, path, domain, secure)
I used routines which I picked up somewhere (can’t remember where):
function setCookie(name, value, expires, path, domain, secure) {
document.cookie= name + “=” + escape(value) +
((expires) ? “; expires=” + expires.toGMTString() : “”) +
((path) ? “; path=” + path : “”) +
((domain) ? “; domain=” + domain : “”) +
((secure) ? “; secure” : “”);
}
function getCookie(name) {
var dc = document.cookie;
var prefix = name + “=”;
var begin = dc.indexOf(“; ” + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else {
begin += 2;
}
var end = document.cookie.indexOf(“;”, begin);
if (end == -1) {
end = dc.length;
}
return unescape(dc.substring(begin + prefix.length, end));
}
David IB