Neballer
11-08-2007, 11:35 PM
I'm not going to pretend that I know that much at all about javascript.
With that being said, I present you with a function that loops through radio buttons from a quiz and checks to see if they're..um..checked. This works, but since the alert is in the loop, I get a pop up for every radio button that's not checked. I only want one.
I tried something along the lines of adding to a message to a variable every time it got into the !checked, but the alert didn't work for me outside the loop. Soooooooodas anyone have any ideas for me.
function validate_form ( ) {
valid = true;
for (var x = 1; x <= 5; x++) {
checked=false;
for (counter = 0; counter < document.pgOneForm.elements['q'+x].length; counter++) {
if (document.pgOneForm.elements['q'+x][counter].checked) {
checked=true;
}
}
if (!checked) {
alert ( "You have not answered question "+[x]+".\n" );
valid = false;
}
}
return valid;
}
With that being said, I present you with a function that loops through radio buttons from a quiz and checks to see if they're..um..checked. This works, but since the alert is in the loop, I get a pop up for every radio button that's not checked. I only want one.
I tried something along the lines of adding to a message to a variable every time it got into the !checked, but the alert didn't work for me outside the loop. Soooooooodas anyone have any ideas for me.
function validate_form ( ) {
valid = true;
for (var x = 1; x <= 5; x++) {
checked=false;
for (counter = 0; counter < document.pgOneForm.elements['q'+x].length; counter++) {
if (document.pgOneForm.elements['q'+x][counter].checked) {
checked=true;
}
}
if (!checked) {
alert ( "You have not answered question "+[x]+".\n" );
valid = false;
}
}
return valid;
}