I'm using Bootstrap buttons as a radio button. http://getbootstrap.com/javascript/#buttons
This is my current code:
<div class="btn-group col-md-2" data-toggle="buttons">
<label class="btn btn-gender btn-default active">
<input type="radio" id="gender" name="gender" value="female"> Girls
</label>
<label class="btn btn-gender btn-default">
<input type="radio" id="gender" name="gender" value="male"> Guys
</label>
</div>
How can I set "male" to checked using JavaScript?
You can check a radio button by default by adding the checked HTML attribute to the <input> element. You can disable a radio button by adding the disabled HTML attribute to both the <label> and the <input> .
By default, any number of checkboxes and radios that are immediate sibling will be vertically stacked and appropriately spaced with .form-check .
<input type="radio"> <input> elements of type radio are generally used in radio groups—collections of radio buttons describing a set of related options. Only one radio button in a given group can be selected at the same time.
Since the male
is a value
attribute, use:
document.querySelector("input[value='male']").checked = true;
document.querySelector
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With