For example, given these radios:
<input type="radio" value="1" name="1_1" required="">True</input>
<input type="radio" value="2" name="1_1" required="">False</input>
and this button (continue to the next page button):
<button type="button" class="d-block mr-0 ml-auto" onclick="return show('Page2','Page1');"> <b>Click here for going to the next page</b></button>
How can I force the user to select at least one radio, before pressing the button? That is, if the user do not select any of the radios, a legend appears saying he needs to answer at least one option? I tried to set the type of the button like this:
<input type="radio" value="1" name="1_1" required="button">True</input>
<input type="radio" value="2" name="1_1" required="button">False</input>
And include this script:
function check(){
var radios = document.getElementsByName("radio");
for (var i = 0, len = radios.length; i < len; i++) {
if (radios[i].checked) {
return true;
}
}
return false;
}
However, both attempts are not working. Any idea about how to force the user to answer before pressing the continue button?