0

I'm trying to check if any one of the three radio buttons having the same class is checked or not, and depending on the result, I want to hide or show another radio button.

var MyThreeRadioButtons = $(".radioButtonsIWantToCheck");
MyThreeRadioButtons.change(function () {
    if (MyThreeRadioButtons.is(":checked")) {
        $(".buttonIwantToHide:radio").hide();
    } else {
        $(".buttonIwantToHide:radio").show();
    }
});

When I added console.log statements to see if the code is invoked, I noticed that the code doesn't run when I uncheck any of the radio buttons.

Curious
  • 47
  • 6

1 Answers1

0

Radio buttons can't be uchecked with interaction (in a group one of them is ever checked) and if you uncheck them via code, the change event is not fired

Pippo
  • 2,173
  • 2
  • 3
  • 16
  • I'm not unchecking them via code. I want to make a decision based on the checked or unchecked state of the radio button. – Curious Mar 17 '23 at 16:48
  • As written before, _'radio buttons can't be unchecked with [human] interaction'_: in a group, one of them is ever checked (except in the initial state) and then `is(":checked")` is ever true. For this purpose you can instead use checkboxes (as @Swati supposed). Otherwise you should explain better your needings – Pippo Mar 17 '23 at 21:12