0

i have a problem need all you guys help me.i set the cookie with javascript when the user make change to the select tag in html code and clear i want to clear it.

* if in php script i just need to clear or delete it , but if in jquery script i need to delete the old one immediately and set a new one of cookie value when the user make change to select tag. let's see the script below.

jquery script

<script type="text/javascript">
  $(function(){
     $('#category').live('change',function(){
       var opt = $('category :seleted').val();
       document.cookie='category_name='+opt; //set the cookie when user make change
       $.ajax({
         type:'POST',
         url : 'getcatetgory.php',
         data : {option : opt},
         success: function(){alert('you have successfully get on category')}
      });
    });
  });
</script> 

html

<select id='category'>
  <option value='car'>Car</option>
  <option value='house'>House</option>
  <option value='sport'>Sport</option>
  <option value='song'>Song</option>
  <option value='phone'>Phone</option>
</selete>

this is i have done with php script.

unset($_COOKIE['category_name']);

but it still doesn't work for me. please guide me

2
  • Don't use $.live(). It's been deprecated and removed fron jQuery. Commented May 14, 2013 at 3:15
  • with php something like setcookie("cookie_name", "", time()-3600); Commented May 14, 2013 at 3:19

1 Answer 1

3

To delete a cookie, you must set a cookie with the same name, path and domain, but with an expiry date that is in the past.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.