SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jun 2014
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How to remove this cookie?

    I am creating a cookie, but I need to remove A cookie based on a onclick event that I am trying to set, but is not working.

    Here is how I am setting the cookie. Which works fine.

    Code:
     <script type="text/javascript">//<![CDATA[ 
     $(window).load(function(){
     $(".filter input").each(function() {
         var mycookie = $.cookie($(this).attr('name'));
         if (mycookie && mycookie == "true") {
             $(this).prop('checked', mycookie);
         }
     });
     $(".filter input").change(function() {
         $.cookie($(this).attr("name"), $(this).prop('checked'), {
             path: '/',
             expires: 365
         });
     });
    
     });//]]>
    And then to delete I am trying to remove the cookie on click event based on an ID with out any luck, I am just not sure where I am going wrong here, would this work... ??? $.removecookie($(this).attr('name'), null, { path: '/' }); see my code below.

    Code:
     <script>
        jQuery('#dnn_ctr555_ProductSearch_rpData_cmdAdvReset_0').click(function()  {
              $.removeCookie($(this).attr('name'), { path: '/' });
         }
    </script>
    Here is a fiddle http://jsfiddle.net/23nUZ/ any help would be awesome.

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    Welcome to the forums

    Your ids are very verbose and make the code hard to read.
    Are you choosing them yourself or are they being generated by something?

    Anyway, if you indent and organize your code correctly (which is as easy as pressing the "Tidy Up" button in JSFiddle), you'll see that this:

    Code:
    //remove cookie on click.
    jQuery('#dnn_ctr555_ProductSearch_rpData_cmdAdvReset_0').click(function()  {
            $.removeCookie($(this).attr('name'), { path: '/' });
          }

    becomes this:

    Code:
    //remove cookie on click.
    jQuery('#dnn_ctr555_ProductSearch_rpData_cmdAdvReset_0').click(function () {
        $.removeCookie($(this).attr('name'), {
            path: '/'
        });
    }
    and it becomes much easier to notice the missing bracket and semi-colon:

    Code:
    //remove cookie on click.
    jQuery('#dnn_ctr555_ProductSearch_rpData_cmdAdvReset_0').click(function () {
        $.removeCookie($(this).attr('name'), {
            path: '/'
        });
    });  <---- here
    Also, is there any reason you switch at random from using the dollar alias to using jQuery?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •