Resetting Radio Button - JQuery Help

  • 28 March 2018
  • 4 replies
  • 112 views

Badge +9

I'm resetting a set of two radio buttons anytime a dropdown value changes. The following works, but how can I combine the two lines into one?

NWF$("#" + DDL).find("input[value='No']")[0].checked=false;
NWF$("#" + DDL).find("input[value='Yes']")[0].checked=false;


4 replies

Userlevel 2
Badge +11

Hi Furst‌,

Have you tried: 

       NWF$("#" + DDL).attr('checked',false);

or

       NWF$("#" + DDL).find("input[name='control name']").attr('checked',false);

or

NWF$("#" + DDL).find("input[name='control name']")[0].attr('checked',false);

Badge +9

I don't think any of that will work as my code looks like this:

var obj = NWF$("#" + DropDownList);obj.change(function() {
NWF$("#" + RadioButtonSet).find("input[value='No']")[0].checked=false;
NWF$("#" + RadioButtonSet).find("input[value='Yes']")[0].checked=false;

});

Userlevel 5
Badge +14

If the target control with the ID stored in the javascript variable called DDL is a radio button, then we know that there will only ever be (1) option checked at any given time. 

Inside of wherever you're handling the change event for your other control, you can use the following code to reset the radio buttons no matter the state or quantity of options:

NWF$("#" + DDL).find("input:checked").prop("checked", false)
Badge +9

Thank you, that worked brilliantly.

Reply