I am an extreme newbie in terms of java script validation so I wouldn't be surprised if literally everything in my code was wrong.
I'm trying to validate my radio buttons.
I previously used this format to try and do it:
if (document.ExamEntry.GCSE.checked == true) {
confirm("You have selected GCSE. Is this correct?");
if (document.ExamEntry.A2.checked == true) {
confirm("You have selected GCSE. Is this correct?");
if (document.ExamEntry.A2.checked == true) {
confirm("You have selected A2. Is this correct?");
because I am wanting it to give a message for each radio button, but of course that didn't work. (The sumbit button worked by forwarding to the next page but the cancel button did the same thing as it wasn't given a command which I didn't know how to do) I was told the onClick command would be good, but I tried it yet failed as I wasn't too sure how to apply it.
So I attempted this: (my now new code)
functioncheckRadio () {
var level = "";
var qualification = document.ExamEntry.Rbutton.value;
var i;
for (i=0; i <qualification; i++) {
if (document.ExamEntry.qualification[i].checked) {
level = document.ExamEntry.Rbutton.value;
break;
}
}
if (level == "") {
document.getElementById("Rbutton").innerHTML = "You must
select a qualification level";
return false;
}
else {
document.getElementById("Rbutton").innerHTML = "";
return = true;
}
}
and this is my html:
<td id="RadioGCSE">GCSE</td>
<td><input type="radio" name="Rbutton" value="GCSE" id="r1" checked = "checked" /></td>
<tr>
<td id="RadioAS">AS</td>
<td><input type="radio" name="Rbutton" value="AS" id="r2" /></td>
</tr>
<td id="RadioA2">A2</td>
<td><input type="radio" name="Rbutton" value="A2" id="r3" /></td>
<tr>
My intentions are to validate each radio button. For example: If GCSE selected then it will come up with this message: "You have selected GCSE. Is this correct" with a submit box that forwards it to the next page when clicked, or a cancel button that just stops the event so that the user stays on the same page so that they can choose another option.
I apologize for the long code/amount of writing. I am an obvious newbie.