0

My actual prob is asp post back issue and html controls.
i try to solve this in this way.

if ($('#rdb1').attr("checked")) {
                document.cookie = $('#rdb1').attr("id");
                check = document.cookie.split(';');
                flag = check[0];

            } else {
                document.cookie = $('#rdb2').attr("id");
                check = document.cookie.split(';');
                flag = check[0];
            }



            if (flag == "rdb1") {
                $('#rdb1').attr("checked", true);
                $('#rdb2').attr("checked", false);


            } if (flag == "rdb2") {
                $('#rdb1').attr("checked", false);
                $('#rdb2').attr("checked", true);
        }

its work.But how to remove cookie i dont know.I search hear and findjavascript - delete cookie I don't want a function.Just want to delete cookies in next button.how to do this?Thanks.

Community
  • 1
  • 1
4b0
  • 21,981
  • 30
  • 95
  • 142
  • Since you're using jQuery, you could give this cookie plugin a try https://github.com/carhartl/jquery-cookie – elclanrs Feb 26 '12 at 04:30
  • @elclanrs there is not any method in java script to delete cookies without function. – 4b0 Feb 26 '12 at 04:41

3 Answers3

0

You can just trigger that function in you button's onclick event..

<script type="text/javascript">
function del_cookie(name)
{
    document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}
</script>
<INPUT TYPE=BUTTON OnClick="del_cookie('put name of cookie here');" VALUE="Clear Cookie"/>
Community
  • 1
  • 1
Shekhar_Pro
  • 18,056
  • 9
  • 55
  • 79
0

I wouldn't recomend the way you are implementing the cookie, I think you should use name/value pairs. But for the actual implementation you are using, to clear the cookie, you can use:

document.cookie = '';

Note that this won't work if you start using name/value pairs because it would only add an empty name/value to your existing cookies.

coseguera
  • 116
  • 3
0

Delete the cookie

And finally, to delete a cookie set its value to null. Note:- Setting it to e.g. an empty string doesn’t remove it; it just clears the value.

$.cookie("example", null);

or

This is a session cookie and will be destroy when user close his/her browser. We can do it like this:

$.cookie("example", "demo", { expires: -1 });

Deepakmahajan
  • 856
  • 1
  • 11
  • 23