ChattanoogaRay
10-26-2003, 08:16 PM
I am placing my firt cookie ever into a single page within my site which will be used only in this page and no where else. I found this cookie script at
http://javascript.internet.com/forms/cookie-form-saver.html
which I am using for my form (contactfm). However I am getting error msg's saying that Error: Object doesn't support this property or method and the line number is for
for(f=1; f<cookieForms.arguments.length; f++) {
can someone help with this as I have never done a cookie before and desperately need the help so I may move forward. Below is all the script I am using:
<script language="JavaScript" type="text/javascript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original: Nick Baker -->
<!-- Begin
// Cookie Functions //////////////////// (:)
var expDays = 100;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1) { endstr = document.cookie.length; }
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
// cookieForms saves form content of a page.
// use the following code to call it:
// <body onLoad="cookieForms('open', 'form_1', 'form_2', 'form_n')" onUnLoad="cookieForms('save', 'form_1', 'form_2', 'form_n')">
// It works on text fields and dropdowns in IE 5+
// It only works on text fields in Netscape 4.5
function cookieForms() {
var mode = cookieForms.arguments[0];
for(f=1; f<cookieForms.arguments.length; f++) {
contactfm = cookieForms.arguments[f];
if(mode == 'open') {
cookieValue = GetCookie('saved_'+contactfm);
if(cookieValue != null) {
var cookieArray = cookieValue.split('#cf#');
if(cookieArray.length == document[contactfm].elements.length) {
for(i=0; i<document[contactfm].elements.length; i++) {
if(cookieArray[i].substring(0,6) == 'select') { document[contactfm].elements[i].options.selectedIndex = cookieArray[i].substring(7, cookieArray[i].length-1); }
else if((cookieArray[i] == 'cbtrue') || (cookieArray[i] == 'rbtrue')) { document[contactfm].elements[i].checked = true; }
else if((cookieArray[i] == 'cbfalse') || (cookieArray[i] == 'rbfalse')) { document[contactfm].elements[i].checked = false; }
else { document[contactfm].elements[i].value = (cookieArray[i]) ? cookieArray[i] : ''; }
}
}
}
}
if(mode == 'save') {
cookieValue = '';
for(i=0; i<document[contactfm].elements.length; i++) {
fieldType = document[contactfm].elements[i].type;
if(fieldType == 'password') { passValue = ''; }
else if(fieldType == 'checkbox') { passValue = 'cb'+document[contactfm].elements[i].checked; }
else if(fieldType == 'radio') { passValue = 'rb'+document[contactfm].elements[i].checked; }
else if(fieldType == 'select-one') { passValue = 'select'+document[contactfm].elements[i].options.selectedIndex; }
else { passValue = document[contactfm].elements[i].value; }
cookieValue = cookieValue + passValue + '#cf#';
}
cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter
SetCookie('saved_'+contactfm, cookieValue, exp);
}
}
}
// End -->
</script>
<body bgcolor="#000066" onLoad="init_page(); cookieForms('open', 'contactfm')" onunload="cookieForms('save', 'contactfm')" onResize="restore()">
http://javascript.internet.com/forms/cookie-form-saver.html
which I am using for my form (contactfm). However I am getting error msg's saying that Error: Object doesn't support this property or method and the line number is for
for(f=1; f<cookieForms.arguments.length; f++) {
can someone help with this as I have never done a cookie before and desperately need the help so I may move forward. Below is all the script I am using:
<script language="JavaScript" type="text/javascript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Original: Nick Baker -->
<!-- Begin
// Cookie Functions //////////////////// (:)
var expDays = 100;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1) { endstr = document.cookie.length; }
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
// cookieForms saves form content of a page.
// use the following code to call it:
// <body onLoad="cookieForms('open', 'form_1', 'form_2', 'form_n')" onUnLoad="cookieForms('save', 'form_1', 'form_2', 'form_n')">
// It works on text fields and dropdowns in IE 5+
// It only works on text fields in Netscape 4.5
function cookieForms() {
var mode = cookieForms.arguments[0];
for(f=1; f<cookieForms.arguments.length; f++) {
contactfm = cookieForms.arguments[f];
if(mode == 'open') {
cookieValue = GetCookie('saved_'+contactfm);
if(cookieValue != null) {
var cookieArray = cookieValue.split('#cf#');
if(cookieArray.length == document[contactfm].elements.length) {
for(i=0; i<document[contactfm].elements.length; i++) {
if(cookieArray[i].substring(0,6) == 'select') { document[contactfm].elements[i].options.selectedIndex = cookieArray[i].substring(7, cookieArray[i].length-1); }
else if((cookieArray[i] == 'cbtrue') || (cookieArray[i] == 'rbtrue')) { document[contactfm].elements[i].checked = true; }
else if((cookieArray[i] == 'cbfalse') || (cookieArray[i] == 'rbfalse')) { document[contactfm].elements[i].checked = false; }
else { document[contactfm].elements[i].value = (cookieArray[i]) ? cookieArray[i] : ''; }
}
}
}
}
if(mode == 'save') {
cookieValue = '';
for(i=0; i<document[contactfm].elements.length; i++) {
fieldType = document[contactfm].elements[i].type;
if(fieldType == 'password') { passValue = ''; }
else if(fieldType == 'checkbox') { passValue = 'cb'+document[contactfm].elements[i].checked; }
else if(fieldType == 'radio') { passValue = 'rb'+document[contactfm].elements[i].checked; }
else if(fieldType == 'select-one') { passValue = 'select'+document[contactfm].elements[i].options.selectedIndex; }
else { passValue = document[contactfm].elements[i].value; }
cookieValue = cookieValue + passValue + '#cf#';
}
cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter
SetCookie('saved_'+contactfm, cookieValue, exp);
}
}
}
// End -->
</script>
<body bgcolor="#000066" onLoad="init_page(); cookieForms('open', 'contactfm')" onunload="cookieForms('save', 'contactfm')" onResize="restore()">