Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing to a cookie

Status
Not open for further replies.

stewartwebb

Programmer
Jan 6, 2004
92
GB
Hi all,

I'm new with cookies but i'll explain what i'm trying to do and if possible can someone point me to a thread thats already covered this topic.

I have the code to create, delete and read a cookie, but what I want to do is be able to write information to the cookie. I'll be writing the user id to the cookie but instead of having a cookie for each user i'd like to have 1 cookie and write each user into that cookie.

I need to find some code that will write the information to the cookie and then some code to loop through the cookie to check each user id when the page loads.

Thanks

Stewart.
 
So decide on a delimiter you can use (comma is a common one) and then comma delimit the usernames before poking them into a cookie with a single key.

You can get the value and use something like split() to split them into an array (which you can then easily iterate over). An alternative would be careful use of indexOf() over the delimited string.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top