Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a simple jquery way to select a radio when checkbox is checked and then deselect the radio when checkbox unchecked?

<input id="myCheckbox" type="checkbox" /> Please, please check me
    <input id="myRadio" type="radio" /> Am I selected ?

I would like the following behavior:

  1. When myCheckbox is checked then myRadio is going to get selected.
  2. When myCheckbox is unchecked then myRadio is going to become unselected.

How will I do this in a very simple way ?

Thank you in advance for your effort to respond.

like image 528
iHello Avatar asked Jan 24 '23 08:01

iHello


1 Answers

$('#myCheckbox').click(function() {
    if ($(this).is(':checked')) {
        $('#myRadio').attr('checked', 'checked');
    } else {
        $('#myRadio').removeAttr('checked');
    }
});
like image 59
Ken Browning Avatar answered Jan 25 '23 21:01

Ken Browning