0

I am new to jQuery. I am working on some cookies script which my cookieA (name of cookie) is null (contains nothing).

When a button is clicked, this script will add 10 to the value of cookieA. And when I click the button again, the value 10 will become 20 and so on.

Here's the script :

$('.button').click(function(){ $.cookie(cookieA, parseInt($.cookie(cookieA).val(),10) +10 , cookieOptions); }); 

Please help me, this is making the value turn into NaN or null .

Thanks and have a wonderful day.

p/s I'm using the script from Klaus Hartly the author of jQuery cookies.

p/s Cookieopstions is the settings for the cookies expiry date etc.

1 Answer 1

0

You want to add 10 to the value of the cookie if the cookie is not null ? or are your trying to add 10 to nothing ?

Maybe you could check your cookie first ?

If ($.cookie(cookieA) == null) { $.cookie(cookieA, 10, cookieOptions); } Else { $.cookie(cookieA, parseInt($.cookie(cookieA).val(),10) +10 , cookieOptions); } 

If i did not understand your question, please let me know,

Regards,

Max

Sign up to request clarification or add additional context in comments.

2 Comments

No , when the button is clicked , it will add 10 to the current existing number . for example , when its null it adds then and it becomes 10 , and when i click the button again it will become 20 .
So what do you get when you debug ? did you try to get each value separately ? Btw, seems like you shouldn't use val() to get the value : stackoverflow.com/questions/6171865/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.