What is a simple jquery way to select a radio when checkbox is checked and then deselect the radio when checkbox unchecked?
-
13-09-2019 - |
Question
<input id="myCheckbox" type="checkbox" /> Please, please check me
<input id="myRadio" type="radio" /> Am I selected ?
I would like the following behavior:
- When myCheckbox is checked then myRadio is going to get selected.
- 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.
Solution
$('#myCheckbox').click(function() {
if ($(this).is(':checked')) {
$('#myRadio').attr('checked', 'checked');
} else {
$('#myRadio').removeAttr('checked');
}
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow