I have this function in my PHP :
setcookie("UserPusser", $user, time() + 604800, "/pusser/beta/");
setcookie("PassPusser", $pass, time() + 604800, "/pusser/beta/");
setcookie("NotifPusser", $notif, time() + 604800, "/pusser/beta/");
And I have this function in my javascript
function getThisCookie(name){
var value;
var singleCookie = document.cookie.split(";")
for(var x in singleCookie){
var y = singleCookie[x].split("=");
if(y[0] == name) {
value = y[1];
}
}
return value;
}
When I type alert(getThisCookie('UserPusser')) the result is what I want. But when I tried to write alert(getThisCookie('NotifPusser')); or alert(getThisCookie('PassPusser')); the result is : undefined.
Anyone can help me?
What I’m trying to do is make the browser remember the value of checkbox each time the page reload.
Just for completeness a full answer here instead of only the hint within the comments:
Cookie values are separated by
;(semicolon + whitespace)This leaves you with something like this:
In order to separate them you have to split them by the same delimiter.
With modern browsers (JS 1.6+ I guess, not quite sure right now) or libraries like underscore.js you could as well put them into an object.
Anyway after performing any of those you can easily access the values you are looking for:
Just remember that those are readOnly. In order to modify them you’d have to write the object back to the
document.cookie