views:

286

answers:

1

im having some difficulty trying to pull out a specific value from a cookie. im using the cookie plugin found here: http://plugins.jquery.com/project/cookie

var cookieString = "{'zip':'" + $( '#ZipCode' ).val() + "','age':'" + $( '#age' ).val() + "','gender':'" + $( '#gender' ).val() +"}";
$.cookie("rememberMe", ( ($( '#rememberMe' ).attr( 'checked' ))?cookieString:null ), { path: '/', expires: 60 });
alert($.cookie("rememberMe"));

which will return correctly:

{'zip':'91210','age':'99','gender':'male'}

now im just having trouble with pulling out specifically one of the items in the array. for example how would i just pull out the value of 'zip'?

+1  A: 

You can use eval to invoke the Javascript compiler and convert the string into an object:

var obj = eval('(' + $.cookie("rememberMe") + ')');
alert(obj['zip']);
karim79
ah, thx... i actually just needed the eval();
leesalo