user3432257
user3432257

Reputation: 415

jquery how to uncheck a radio button in this code

I have two radio button.

and this is my jquery code to unselect the radio button when the other one becomes selected.

 $("#RdbToday").click(function () {
        $("#RdbDateRange").attr("checked", false);
    }); 
    $("#RdbDateRange").click(function () {
        $("#RdbToday").attr("checked", false);
    });

It is not working. which means that when I select the first one, the other one still on. also I can't unchecked the radio button once I checked it. why?

Upvotes: 0

Views: 48

Answers (2)

Just code
Just code

Reputation: 13801

Millind's answer right i am posting this alternative way you can use prop name

of html Like this

<input type="radio" name="foo">
<input type="radio" name="foo" checked>
<input type="radio" name="foo">

See working demo

Demo

As your comment says you are using asp.net then its very simple to use groupname attribute Read here.....http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobutton.groupname(v=vs.110).aspx

Upvotes: 1

Milind Anantwar
Milind Anantwar

Reputation: 82241

use .prop() instead:

$('radio_btn_selector').prop('checked', false);

Upvotes: 2

Related Questions