views:

267

answers:

1
First showing the cookie, use this code from: electrictoolbox.com/javascript-get-all-cookies/

Then i made a form to add some cookie

<form class="cokies" method="post">
<input class="query" name="q" type="text" />
<input type="submit" name="save" value="saving">
<a>Delete Cookies</a>
</form>


$(document).ready(function(){
$('.cokies a').click(function(){
 $.cookie('q', null);
});

remember('[name=q]');

this function from : komodomedia.com/blog/2008/07/using-jquery-to-save-form-details/

function remember( selector ){
 $(selector).each(function(){
  //if this item has been cookied, restore it
  var name = $(this).attr('name');
  if( $.cookie( name ) ){
   $(this).val( $.cookie(name) );
  }

  //assign a change function to the item to cookie it
  $(this).change(function(){
   $.cookie(name, $(this).val(), { path: '/', expires: 365 });
  });
 });
}

the problem is, i can't delete a cookie

+1  A: 

To delete the cookie, simply set the expires: to a negative integer value.

example:

$.cookie(name, $(this).val(), { path: '/', expires: -5 });

thephpdeveloper
yes, it's work. thank you
Agus Puryanto
if it works give it a tick and others who come to this question knows the correct answer.
thephpdeveloper