client side validation of radio buttons / multiple choice questions
i have 10 questions with each three possible options, answered by radio buttons. im trying to use JS to validate the form, to check if a question has been unanswered.
this is my code for question 1. it works but im not sure if this is the best way to go about it. also, i have to repeat this block of code 10 times, once for each question. im sure thats NOT the best way to go about it
its quite a difficult concept since i have to evaluate everyting per three possible answers. i also want to show an inline alert at the unanswered question, so i cant just check for 10 checked radio buttons.
anyone know a better way to get around this?
Code:
function alertMe() {
one = document.getElementById("q11");
two = document.getElementById("q12");
three = document.getElementById("q13");
if ( (one.checked == true) || (two.checked == true) || (three.checked == true) ){
window.alert ('at least one is checked');
}
else {
window.alert ('none checked');
}
}