Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery, How to unselect all radio button in radio group

Anyone know how to unselect all radio buttons in a radio group ?

HTML:

<div id="emptimfields">               <label id="lbl_emptim">How regulary do you employ people to help cultivate your land? </label><br/><br/>               <fieldset data-role="controlgroup" data-type="vertical" id="emptim">                <input name="emptim" id="radio1" value="fromtimetotime" type="radio" openmrs-valuecoded="" />               <label for="radio1"> From time to time </label>                <input name="emptim" id="radio2" value="allthetime" type="radio" openmrs-valuecoded="" />               <label for="radio2">All the time</label>                <input name="emptim" id="radio3" value="dontknow" type="radio" openmrs-valuecoded="" />               <label for="radio3"> Don't know </label>              </fieldset>         </div> 

JQuery side:

$('input:radio[name=emptim]:checked').prop('checked', false); // doesn't work  

I'm certainly missing something basic, but I can't figure out what is the problem.

First, I check Yes and then check a value of the second radio group :

enter image description here

Then, I check No to hide the second radio group:

enter image description here

Then, If I click on next, I get the value of what I've checked (but I checked no previously, so here I don't want an alert, I want the radioButton "From time to time" to be unchecked) :

enter image description here

Finally, if I come back, nothing happend :

enter image description here

like image 483
Alexis C. Avatar asked Aug 21 '12 12:08

Alexis C.


People also ask

How do I deselect all radio buttons?

If you want to uncheck all the radio buttons and checkboxes you will need to add one single line (in bold): $('#clear-all'). click(function () { $(':checkbox'). each(function () { $(this).

How do you uncheck a radio button?

To set a radio button to checked/unchecked, select the element and set its checked property to true or false , e.g. myRadio. checked = true .


1 Answers

You can give them a classname and try:

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

When you use an older version of jQuery than 1.6 it has to be:

 $('<selector>').attr('checked', false); 

EDIT :

Call the method .checkboxradio("refresh"); has also worked for me.

like image 154
Roel Avatar answered Sep 23 '22 10:09

Roel