I have a code that I got from bootstrap and I want to know how to get the value of the radio button when the user clicks on it.
<div class="d-flex justify-content-center">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="5">
<label class="form-check-label" for="inlineRadio1">5 stars</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="4">
<label class="form-check-label" for="inlineRadio2">4 stars</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio3" value="3">
<label class="form-check-label" for="inlineRadio3">3 stars</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio4" value="2">
<label class="form-check-label" for="inlineRadio3">2 stars</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio5" value="1">
<label class="form-check-label" for="inlineRadio3">1 star</label>
</div>
</div>
3
Answers
You can attach click event to radio buttons, access the clicked radio button’s value using
this
keyword:You can get all the radio elements with same name and then add an event listener to get the checked item
You can use this jQuery to get value