By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,478 Members | 1,610 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,478 IT Pros & Developers. It's quick & easy.

javascript cookies

100+
P: 178
Hi,

I have set two cookies in my previous page. When I use an alert to show the value of the cookies this is the format I get.

auth=1;project=4

I wan to use javascript to get the value of the project cookie. Does anyone know of a way I can do this?
Aug 20 '08 #1
Share this Question
Share on Google+
2 Replies


100+
P: 178
Ive worked it out using a split function

here it is

Expand|Select|Wrap|Line Numbers
  1. var cokie = document.cookie;
  2. // alert(cokie);
  3. var splitCookie = cokie.split("=");
  4.     var proj = splitCookie[2]; // this is the value of proj_id extracted from the cookie
  5.     // alert(proj);
Aug 20 '08 #2

acoder
Expert Mod 15k+
P: 16,027
That would assume that the project value is always the second item in the cookie. If you want something more reliable, try the scripts in either this link or this one.
Aug 20 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.