Forum Moderators: open

Message Too Old, No Replies

Set cookie with value as variable

Set cookie with value as variable in javascript

         

achshar

3:19 pm on Nov 19, 2009 (gmt 0)

10+ Year Member



Hello everybody...
I am a javascript newbie and need some hellp correcting the document.cookie code below. It is not working for some reason. It works if i dont use the variable for value and simply give plain function... i have tried in chrome beta 3 and ie 8
please correct me or suggest me anything else...

[codes]
function changeColor(value)
{
document.cookie = "changeColor =" + escape(value) + ";expires=Wed, 01-Jan-2070 00:00:01 GMT";
}
[/codes]
I'v been working with php for a while but in this case cookie has to be set without page load/refresh so php wont help..
Thanks in advance.

achshar

5:35 pm on Nov 21, 2009 (gmt 0)

10+ Year Member



anybody?

Fotiman

2:56 pm on Nov 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The only thing I notice that might be problematic is that you have a space between changeColor and the equal sign that follows it. I would remove that space, then try it again.

achshar

4:29 pm on Nov 23, 2009 (gmt 0)

10+ Year Member



ohh me bad... i got it working now dont know it was the space or the pc. I tried without space on another pc, uploaded it and it worked! Thanks lot anyways. Really helped..