<script type="text/javascript">
let x = "1.html";
let y = "2.html";
function redirectPage(form){
for(let i=0; i<form.length; i++) {
if(form.answerq[i].checked && form.answerw[i].checked && form.answere[i].checked) {
if (form.answerq[i].value == 'a' && form.answerw[i].value == 'a' && form.answere[i].value == 'a') {
window.location = x;
} else {
window.location = y;
}
}
}
}
</script>
<form method="post" action="#">
*ARE YOU 18+ YEARS OLD?
<label><input type="radio" name="answerq" value="a"> Yes</label>
<label><input type="radio" name="answerq" value="b"> No</label>
*ARE YOU A U.S CITIZEN?
<label><input type="radio" name="answerw" value="a"> Yes</label>
<label><input type="radio" name="answerw" value="b"> No</label>
*ARE YOU MARRIED?
<label><input type="radio" name="answere" value="a"> Yes</label>
<label><input type="radio" name="answere" value="b"> No</label>
<button type="button" class="btn btn-primary" value="Submit" onclick="redirectPage(this.form)">Submit!</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</form>
Selecting yes,yes,yes or no,no,no is working perfectly fine and redirect to the correct link. However, when selecting yes,yes,no, no,yes,no or yes,no,yes doesn't work after clicking the submit button.
And one more thing anyone here can help me put a validation if they do not select a radio button like an alert of prompt?