Hi all,
I did a search, and did find some useful information, but I'm still getting a Javascript error.
I have a checkbox array, and I want to validate to ensure at least one checkbox is checked before allowing user to submit the form.
Relevant HTML code:
Relevant Javascript code: (external file - checkform.js)
Javascript error:
Why doesn't obj have properties? I thought I assigned properties to it in the line: obj = aForm.elements['program'];
Thanks for your time.
![[cheers] [cheers] [cheers]](/data/assets/smilies/cheers.gif)
Cheers!
Laura
I did a search, and did find some useful information, but I'm still getting a Javascript error.
I have a checkbox array, and I want to validate to ensure at least one checkbox is checked before allowing user to submit the form.
Relevant HTML code:
Code:
<script language="javascript" type="text/javascript" src="checkform.js"></script>
<form name="add" method="post" action="save.php?tableid=18" onSubmit="return CheckForm(this)">
<input type="checkbox" name="program[1]" value="Program one">
Program one<br>
<input type="checkbox" name="program[2]" value="Program two">
Program two<br>
<input type="checkbox" name="program[3]" value="Program three">
Program three<br>
<input type="checkbox" name="program[4]" value="Program four">
Program four<br>
<input type="checkbox" name="program[5]" value="Program five">
Program five<br>
<input type="checkbox" name="program[6]" value="Program six">
Program six<br>
<input type="checkbox" name="program[7]" value="Program seven">
Program seven
</form>
Relevant Javascript code: (external file - checkform.js)
Code:
function CheckForm(aForm){
var errorString = "The following problems occurred: \r\r";
var validHandle = true;
obj = aForm.elements['program'];
var txt = "";
for (i = 0; i < obj.length; i++) {
if (obj[i].checked) {
txt = txt + obj[i].value + " ";
}
}
if (txt == "") {
validHandle = false;
errorString += "Program not chosen. \r";
}
else {
validHandle = true;
}
if (validHandle == false) {
errorString += "\r";
alert(errorString+'\nPlease make changes and submit the form again.');
}
return (validHandle == true)
}
Javascript error:
Code:
Error: obj has no properties
Source File: checkform.js
Line: 7
Why doesn't obj have properties? I thought I assigned properties to it in the line: obj = aForm.elements['program'];
Thanks for your time.
![[cheers] [cheers] [cheers]](/data/assets/smilies/cheers.gif)
Cheers!
Laura