Click to See Complete Forum and Search --> : problem with validation of radio buttons


tuanyong
09-11-2003, 10:53 PM
hi all ,
i had searched the forum for past threads and did according to how to validate the radio buttons but after i have tried it in my script it can't work ..

<script type="text/javascript">
function validateForm ()
else if(document.booking.brand[0].checked || document.booking.brand[1].checked || document.booking.brand[2].checked || document.booking.brand[3].checked || document.booking.brand[4].checked)
{
alert("Please choose the brand intended for usage!");
document.booking.brand[0].focus();
return false;
}
else{
return true;
}

</script>

<form name="booking" method="POST" action="booking.asp "onSubmit="return validateForm();">
<td width="82%"><p><input type="radio" value="Avaya" name="brand"> <b><font face="Abadi MT Condensed Light" size="4" color="black">Avaya&nbsp;</font></b>
<input type="radio" value="Cisco" name="brand"> <b><font face="Abadi MT Condensed Light" size="4" color="black">Cisco</font></b>
<input type="radio" value="Nortel" name="brand"> <b><font face="Abadi MT Condensed Light" size="4" color="black">Nortel</font></b>
<input type="radio" value="Ericsson" name="brand"> <b><font face="Abadi MT Condensed Light" size="4" color="black">Ericsson</font></b>
<input type="radio" value="Application" name="brand"> <b><font face="Abadi MT Condensed Light" size="4" color="black">Application&nbsp;</font></b></p>
</td>

after i clicked submit with no radio button checked, nothing happens and it just go through to the next page ..
can someone help !!

Jona
09-11-2003, 11:57 PM
Turn "else if" into just plain ol' "if." And then negate the possibilities (put ! in front of them). Like this:


function validateForm(){
if(!document.bookform.brand[0].checked || !document.bookform.brand[1].checked || //etc


[J]ona

tuanyong
09-12-2003, 12:26 AM
joan, thanks a lot

it works with the ! and i realized that i have to change the
"||" to "&&" so that it can work ...

tuanyong

Jona
09-12-2003, 10:37 AM
Ah, didn't pick that up. You're welcome, though.

[J]ona