You can validate the radio button in a form is selected or not with the help of javascript.
<div class="radio-buttons"> <div class="male"> <input class="form-radio" type="radio" name="gender" id="radio1" value="male"> <label class="form-check-label" for="radio1">Male</label> </div> <div class="female"> <input class="form-radio" type="radio" name="gender" id="radio2" value="female"> <label class="form-check-label" for="radio2">Female</label> </div> </div>
Here you can check it by document.querySelectorAll() with the help of attribute name,
var checkedInputRadio = document.querySelectorAll("input[name='gender']:checked"); if (checkedInputRadio.length) { var getRadioValue = checkedInputRadio[0].value; console.log(getRadioValue); }
Here, the checkedInputRadio variable fetches the checked result from the Form and if any input radio is selected, it will display the value of the selected radio button.
This is the simplest way to check and get the value of the selected input radio button.