Does anyone know how to check a radio input with jQuery?
I was thinking val() would work but apparently it only sets the value on text inputs.
$('[name="radio_group"]').val('my_selected_value');
Nothing happens if I do that
Does anyone know how to check a radio input with jQuery?
I was thinking val() would work but apparently it only sets the value on text inputs.
$('[name="radio_group"]').val('my_selected_value');
Nothing happens if I do that
Put the selected value into the selector, and set the checked
property.
$('[name="radio_group"][value="3"]').prop('checked', true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="radio" name="radio_group" value="1">1<br/>
<input type="radio" name="radio_group" value="2">2<br/>
<input type="radio" name="radio_group" value="3">3<br/>
$('[name="radio_group"]').prop('checked',true);
This assumes that there is only one item with name ='radio_group'.