I want to prevent the form ( with id="new_question") from being submitted if an answer (radio button) is not checked from that radio group.
<input class="radioclass" id="q1a" value="a" name="question[q1correct]" type="radio">
<input class="radioclass" id="q1b" value="b" name="question[q1correct]" type="radio">
<input class="radioclass" id="q1c" value="c" name="question[q1correct]" type="radio">
<input class="radioclass" id="q1d" value="d" name="question[q1correct]" type="radio">
<input id="publishbtn" class="greenbtn" type="submit" value="PUBLISH" name="commit"></input>
There are ten radio groups (with the same html above) that require one answer checked.
The form id is "new_question"
So need help making a validation that doesn't allow the form to be submitted unless all the answers are checked.
What I have so far:
validateForm = function() {
x = document.forms['new_question']['question[q1correct]'].value;
if (x === null || x === '') {
alert('Name must be filled out');
return false;
}
};
I do need this for the rest of the 10 radio groups but I think once I know how to do it on one, I can implement the code on all the radio groups.