MayThrow
MayThrow

Reputation: 2201

variable inside Cookie name

I tried inserting a variable in cookie name

jQuery.cookie("box'+ variablename +'","open", {expires: 365});

What am i doing wrong here?

Upvotes: 0

Views: 219

Answers (3)

muck41
muck41

Reputation: 288

the name of cookie you are trying to save will look like this

box'VariableName'

Remove the single parenthesis.

Upvotes: 0

gaspyr
gaspyr

Reputation: 353

jQuery.cookie("box"+ variablename ,"open", {expires: 365});

Upvotes: 6

gen_Eric
gen_Eric

Reputation: 227310

You forgot the a " before and after the +.

jQuery.cookie("box'"+ variablename + "'","open", {expires: 365});
//-----------------^-----------------^

Do you really want the ' inside of the string? You probably don't. In that case lose the 's.

jQuery.cookie("box"+ variablename, "open", {expires: 365});

Upvotes: 4

Related Questions