Click to See Complete Forum and Search --> : Help with error


bsd12673
11-26-2003, 10:51 AM
I'm trying to loop through 11 radio buttons and make sure that they are not blank with the following code, can someone tell me what I'm missing, I keep getting a syntax error but I'm not seeing why.

This code is inside of a function with a bunch of other else if statements.

else if (document.forms.checkform.srf_projman.value == "")
{
alert("Please Enter your Project Manager");
document.forms.checkform.srf_projman.focus();
return false;
}
for (i = 0; i < document.forms.checkform.srf_market_type.length; i++) {else if (!document.forms.checkform.srf_market_type[i].checked) {
alert("Please select a market Segment");

return false;
}

}

else {
return true;
}
}

Pittimann
11-26-2003, 11:36 AM
Hi!

First of all: there is a bracket too much at the end (maybe the end of your function?).

Second: the else if after your "for" has to be before the loop. (as I handled the stuff differently, in my example it is no longer an else if but the terminating else)

Third: there is a problem with "document.forms.checkform.srf_market_type.length"

Try something like that:
-----------------
//previous conditions above
var radios=11;//number of radio buttons
else if (document.forms.checkform.srf_projman.value == "") {
alert("Please Enter your Project Manager");
document.forms.checkform.srf_projman.focus();
return false;
}
else {
var z=0;
for (i = 0; i < radios; i++) {
if (!document.forms.checkform.srf_market_type[i].checked) {
z ++;
}
}
if (z==radios){
alert("Please select a market Segment");
return false;
}
if (z!=radios){
alert("ok");
return true;
}
}
//if your bracket was the end of the function add a "}" here
-----------------
I'm sure that one of the Gurus here will solve it more professionally; but like this it works...
Cheers - Pit