Hi there, I have the following script to validate a form radio button. The visitor is registering for a class and they must choose a class before moving on. This script works great with a list of items but if there is only one item and even when it's selected, the alert box comes up anyway. The list pulls from a SQL database. Any ideas on how to fix this or a better way to handle it would be greatly appreciated. Thanks in advance!
Code:
<script language="JavaScript">
function validateForm() {
with (document.frmStates) {
var alertMsg = "You must choose a course to register.";
radioOption = -1;
for (counter=0; counter<register.length; counter++) {
if (register[counter].checked) radioOption = counter;
}
if (radioOption == -1) alertMsg += "\nregister";
if (alertMsg != "You must choose a course to register.") {
alert(alertMsg);
return false;
} else {
return true;
} } }
</script>