[Javascript] Validating a radio button

richf at ukonline.co.uk richf at ukonline.co.uk
Wed Jan 14 14:38:12 CST 2004


Hi all,

I use this script to error check some drop down boxes which works fine e.g.
modefrom. But how can I use the same syntax for the radio buttons I have e.g.
carshare ? None of the following bits for the radio button carshare work !

Thanks in advance for any help.

Richard

<script LANGUAGE="JavaScript">
function checkFields() {
missinginfo = "";

if(document.form.modefrom.value == "-1") {
missinginfo += "\n     -  How your child travels from school";
}
if(document.form.carshare.checked) {
missinginfo += "\n     -  Whether you would car share";
}
if(document.form.carshare.checked == false) {
missinginfo += "\n     -  Whether you would car share";
}
if(document.form.carshare.selected == false) {
missinginfo += "\n     -  Whether you would car share";
}

if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"You failed to correctly fill in your:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter this information \nand press the submit button";
alert(missinginfo);
return false;
}
else return true;
}
</script>

----------------------------------------------
This mail sent through http://www.ukonline.net



More information about the Javascript mailing list