How to enable or disable radio button based on check box selection in Jquery ?

chokka
chokka used Ask the Experts™
on
How to enable or disable radio button based on check box selection in Jquery ?

Check box click function is written inside the ready. function.

 $("#Other").on("click", function ()
    {
        if ($("#Other").is(":checked"))
        {   
            document.getElementById('Yes').disabled = false;
            document.getElementById('No').disabled = false;
        }
        else
        {
            document.getElementById('Yes').disabled = true;
            document.getElementById('No').disabled = true;
        }
    });
    $("#Other").trigger("click");

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
HTML
    <input type="checkbox" id="Other" name="other" />
    <input type="radio" id="Yes" value="yes" name="something" disabled/> Yes
    <input type="radio" id="No" value="yes" name="something" disabled/> No

Open in new window

jQuery
<script>
$(function() {
  $("#Other").on("click", function () {
    if ($("#Other").is(":checked")) {   
      $('input[name="something"]').prop({disabled: false});
    }
    else {
      $('input[name="something"]').prop({disabled: true});
    }
  });
});
</script>

Open in new window

Working sample here
chokkaStudent

Author

Commented:
It doesn't have a trigger event. In my study from online, click function needs a trigger event to fire
chokkaStudent

Author

Commented:
Thank you Julian, I will accept as solution. However, the solution which I have has. Trigger event to fire the click function
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
I can add the trigger event - by why do you need it? Why not just set the state of the checkbox and radio's to what you want when the page loads?
chokkaStudent

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial