GetDotted Domains

Viewing Thread:
"JavaScript - cookies and strings"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Sun 07/12/03 at 15:27
Regular
"It goes so quickly"
Posts: 4,083
Hi all,

I'm having a little trouble figuring out how to extract information stored in a cookie.

The cookie contains multiple values, each separated by a comma (,) but isn't splitting as I'd like it.

The cookie reads as: "visits=page1=19,page2=7,page3=16,page4=12" (where 'visits' is the cookie name and
'page1=19,page2=7,page3=16,page4=12' is the cookies value)

I've already used the split(";") method to break up multiple cookies, but now I want to break up the cookie name and value into two stores so the values would be stored like so:

cookie[0] = "visits";
cookie[1] = "page1=19,page2=7,page3=16,page4=12";

At which point I would use split(","); to break up each individual page hit.

However, I am only able to get as far as using the split method to break up the string at each '=', rather than just the first, so the results appear as:

cookie[0] = "visits";
cookie[1] = "page1";
cookie[2] = "19,page2";
cookie[3] = "7,page3";
cookie[4] = "16,page4";
cookie[5] = "12";

This makes using the values a lot harder.

I'm a little rusty with strings when it comes to JavaScript, so I am wondering if anyone can give me the code which will split up the cookie string by the first '=' sign, and only the first one??

Any help is appreciated.
There have been no replies to this thread yet.
Sun 07/12/03 at 15:27
Regular
"It goes so quickly"
Posts: 4,083
Hi all,

I'm having a little trouble figuring out how to extract information stored in a cookie.

The cookie contains multiple values, each separated by a comma (,) but isn't splitting as I'd like it.

The cookie reads as: "visits=page1=19,page2=7,page3=16,page4=12" (where 'visits' is the cookie name and
'page1=19,page2=7,page3=16,page4=12' is the cookies value)

I've already used the split(";") method to break up multiple cookies, but now I want to break up the cookie name and value into two stores so the values would be stored like so:

cookie[0] = "visits";
cookie[1] = "page1=19,page2=7,page3=16,page4=12";

At which point I would use split(","); to break up each individual page hit.

However, I am only able to get as far as using the split method to break up the string at each '=', rather than just the first, so the results appear as:

cookie[0] = "visits";
cookie[1] = "page1";
cookie[2] = "19,page2";
cookie[3] = "7,page3";
cookie[4] = "16,page4";
cookie[5] = "12";

This makes using the values a lot harder.

I'm a little rusty with strings when it comes to JavaScript, so I am wondering if anyone can give me the code which will split up the cookie string by the first '=' sign, and only the first one??

Any help is appreciated.

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Impressive control panel
I have to say that I'm impressed with the features available having logged on... Loads of info - excellent.
Phil
Second to none...
So far the services you provide are second to none. Keep up the good work.
Andy

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.