PDA

View Full Version : js cookie - output one at a time?


homerUK
05-20-2003, 01:55 PM
Hi,

I have a set of cookies, all named:

page + pageNo = "value"

they all work perfeclty.... but I need to output all the cookies which begin with "page" then get their value......

for example..

page1 = "max"
page2 = "max"
page3 = "min"

there will be no set number of pages... so I need a for loop which will go through the document.cookies list, getting each page number and its value... possibly loading it in to an array.

any ideas??

thanks v much!!

Catman
05-20-2003, 03:01 PM
I'd assign a one digit or one letter code to the value. If you've only 2 values, then 0 and 1 would do.

I'd then use an array to store the values. When you're ready to store the cookie, use the toString method on the array (such as pageString=pageArray.toString(); ), then make the cookie like this: page = pageString.

When retrieving the cookie, you'll need to split it and populate the array something like this:

pageString = getPageCookie(); //your cookie retrieval function
for (count=0; count<pageCountMax; count++)
{
pageArray[count] = pageString.substr(count,count+1);
}

In short, you end up making only one cookie and using each character to store information about the pages.