Reputation: 1022
Im using chkArray.push($(this).val());
and document.cookie = 'ids='+chkArray;
within a $('input[type=checkbox]:checked').each(function()
to store checkboxes values.
Then with a simple onclick function (AJAX) fecth products info from db and display in a div.
So far it is working well, but :
How can I reset / Delete the {name:values} created with document.cookie
after the onlick event ?
I tried document.cookie.length = 0; and chkArray.length = 0;
but it is not working.
How to call the Array with the ids/values ? When I use the debugging console in chrome I can see under cookies Name(ids) and values ( XXX,XXX )
If I want to store different values within the same function using document.coolie
, will it replace the first pair (key:value) created from the checkboxes or added to it?
var x = 'abcd';
document.cookie = 'XName='+x;
thanks
Upvotes: 0
Views: 56
Reputation: 21
Since you are already using jQuery, you can have a look at this plugin : jquery-cookie to help you with your problems.
Upvotes: 1
Reputation: 775
document.cookie = ''
. You can empty an array with chkArray = []
document.cookie = 'ids=hi; name=Han'
. Now you have a cookie with two key-value pairs. ids
and name
.array.join(',')
. You get a comma seperated list of idsUpvotes: 1