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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retreiving multiple cookies

Status
Not open for further replies.

tbuch

Programmer
Oct 17, 2000
80
US
I am having a problem with cookies. I have another script that stores the following cookies:

username
luckynumber
sign

I am trying to retrieve the cookies and assign the cookie names as the indices of an array and the cookie values as the corresponding values in the array. When I try to display the values, all but the first are undefined.

Code:
[blue]if( document.cookie ) {
   var myCookie = document.cookie;
   var temp = myCookie.split( ";" );
   var cookies = new Array( temp.length );

   for( var i = 0; i < temp.length; i++ ){
      var hold = temp[ i ].split( "=" );
      cookies[ hold[ 0 ] ] = hold[ 1 ];
   }

   document.write( "Username: " + cookies[ "username" ] +
      "<br />Lucky Number: " + cookies[ "luckynumber" ] +
      "<br />Sign: " + cookies[ "sign" ] );
}[/blue]

Any clues?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top