javascript - Expire check boxes cookies on click button -
i have multiple checkboxes in datatable 1 name , different values can store cookie checkbox in checked following code
$(document).ready(function(){ $('input[type=checkbox]').each(function() { var mycookie = $.cookie($(this).attr('value')); if (mycookie && mycookie == "true") { $(this).prop('checked', mycookie); } }); $('input[type=checkbox]').change(function() { var date = new date(); var uncheckdate = new date(); // expire cookies after 1 day if checked date.settime(date.gettime() + (1 * 24 * 60 * 60 * 1000)); // expire cookies after 1 seconds if unchecked uncheckdate.settime(date.gettime() + ( 1 * 1000)); $.cookie($(this).attr("value"), $(this).prop('checked'), { path: '/', expires: date }); $.cookie($(this).attr("value"), $(this).prop('unchecked'), { path: '/', expires: uncheckdate }); }); });
also can expire cookie each checkbox if unchecked
but need use button example expirebutton expire checkboxes checked.
how can achieve ?
any suggestions ?
you can try below:
$('.expirebutton').on('click',function() { var uncheckdate = new date(); uncheckdate.settime(date.gettime() + ( 1 * 1000)); $.each($('input[type=checkbox]:checked'),function(){ //get checked checkbox $.cookie($(this).attr("value"), { path: '/', expires: uncheckdate }); }); });
Comments
Post a Comment