Forum Moderators: open

Message Too Old, No Replies

Array index into cookie

         

101Jen

10:00 am on Sep 16, 2008 (gmt 0)

10+ Year Member



Hello, I found this good setCookie function that sets cookies to expire for days in this case its set to expire in a whole year

function setCookie(name,value,days)
{var expires = "", date = new Date();
if(days)expires = "; expires=" + new Date(date.setDate(date.getDate()+days)).toGMTString();}
setCookie('i', 'index', 365);

In this case the cookie name is set to "i" the cookie value is set to "index" and is set to expire in a year 365.

Then I have an array and it grabs the array index number that is currently being used. So if array number [2] is currently being used the code grabs the 2.

var array=[];
array= ["stuff"]; (webmaster world not including first number)
array[2] = ["stuff2"];
array[3] = ["stuff3"];

the index number that was grabbed is stored in the javascript variable index. Or var index

Which all works fine tested with alert(index); which shows the current number it grabbed and that array is using.

I need help to know how to get that number grabbed each time into a cookie? I tried setCookie('x', 'index', 365);
But when I test it in an alert, alert( document.cookie = name+"="+value+expires+"; path=/" ); where it shows all the cookie values read, it shows the cookie value as the word "index" instead of the number index has grabbed.

Please let me know how to set the array index into a cookie. Thank you very much.

[1][edited by: 101Jen at 10:05 am (utc) on Sep. 16, 2008]

daveVk

10:28 am on Sep 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



close, try setCookie('x', index, 365);

101Jen

6:44 pm on Sep 16, 2008 (gmt 0)

10+ Year Member



Thanks thats what it was.