Anyone have any idea why this is giving me the error that "checkBox[...].checked is null or not an object". I need the form field to be named RelatedCheck[] for PHP but the javascript doesn't like it. Here is my code.
<!-- * Javascript procedure *** -->
<script language="javascript">
function validateDetailForm() {
// ****** Check to see if more than four checkboxes were selected, if so set error flag
checkBox=document.Details.elements['RelatedCheck[]'];
var num_Related = checkBox.length;
var checkCount = 0;
for(var i=0;i <= num_Related;i++) {
if(checkBox[i].checked == true) {
checkCount++;
}
}
if(checkCount > 4) {
alertMessage = alertMessage + "- You have selected more than 4 Related Criteria. Please select 4 or fewer related criteria.\n";
alertFlag = 1;
}
// ****** If an alert has been triggered, display the alert to the user, else continue with submit ******
if (alertFlag == 1){
alertMessage = alertMessage + "\nPlease correct the following errors and resubmit this page. Thank You.";
alert (alertMessage);
return false;
} else {
return true;
}
}
</script>
<!--- * HTML Form * -->
<form name="Details" method="post" action="details.php" onSubmit="javascript:return validateDetailForm();">
<input type='checkbox' name='RelatedCheck[]' value='4'><br>
<input type='checkbox' name='RelatedCheck[]' value='5'><br>
<input type='checkbox' name='RelatedCheck[]' value='6'><br>
<input type='checkbox' name='RelatedCheck[]' value='7'><br>
<input type='checkbox' name='RelatedCheck[]' value='8'><br>
<input type='checkbox' name='RelatedCheck[]' value='9'><br>
<input type='checkbox' name='RelatedCheck[]' value='10'><br>
<input type='checkbox' name='RelatedCheck[]' value='11'><br>
<input type='checkbox' name='RelatedCheck[]' value='12'><br>
<input type='submit' name='Save' value='Save'>
</form>