Posts: 1
Location: Tampa Bay, FL - USA
|
Hi,
I am working validating an HTML form using Javascript. I wrote a function to validate radio groups and it doesn't seem to be working. I can tell, because the alert message should pop up if I leave the group unchecked.
I am attaching the code - Any help is appreciated.
<head>
<script language="JavaScript" type="text/JavaScript">
function validRadio(formField[i], fieldLabel, num) {
var result = true;
for (i=0, i<num, i++) {
if (!(formField[i].checked)) {
alert('Please select an answer for "' + fieldLabel + '".');
formField.focus();
result = false;
}
}
return result;
}
function validateForm(orientation){
if (!validRadio(orientation.enroll[],"Enrollment Time",3))
return false;
if (!validRadio(orientation.BFscholar[],"Bright Futures recipient",2))
return false;
if (!validRadio(orientation.prog[],"participation in special USF programs",2))
return false;
return true;
}
</script></head>
</body>
<FORM id="orientation" name="orientation" method="post" onSubmit="return validateForm(this)" action="name@domain.com">
<br><input type="radio" name="enroll" id="enroll" value="less">Less than half time (1 - 5 credit hours)
<br><input type="radio" name="enroll" id="enroll" value="half">At least half time (6 - 11 credit hours)
<br><input type="radio" name="enroll" id="enroll" value="full">Full time (12 or more credit hours)
<input type="radio" name="BFscholar" id="BFscholar" value="yes">Yes</td>
<input type="radio" name="BFscholar" id="BFscholar" value="no">No</td>
<input type="radio" name="prog" id="prog" value="yes">Yes</td>
<td width="25%"><input type="radio" name="prog" id="prog" value="no">No</td>
</form></body>
|