Javascript's Journal
[Most Recent Entries]
[Calendar View]
[Friends View]
Monday, December 18th, 2006
| Time |
Event |
| 2:07p |
Validating checkbox[] array (solved..thanks) I can't figure out how to access each labno[] value in my validation loop. The following example results in 5 messageboxes appearing - the first says 4, then undefined, undefined, undefined, undefined.
If I remove the apostrophes around labno[] (in the second alert line), the script dies with an error.
I'm stuck here and would greatly appreciate any pointers..
Code: <script type="text/javascript">
function CheckForm33(theForm)
{
labnos = document.frmAdd.elements['labno[]'].length;
alert(labnos);
for(i=0; i< labnos; i++)
{
alert(document.frmAdd.elements['labno[]'].value);
}
}
</script>
<form name=frmAdd onsubmit='javascript: return CheckForm33(this);'>
<input type=checkbox name='labno[]' value=11><br>
<input type=checkbox name='labno[]' value=22><br>
<input type=checkbox name='labno[]' value=33><br>
<input type=checkbox name='labno[]' value=44><br>
<input type=submit>
</form> EDITED: Fixed with the following CheckForm33 function: function CheckForm33(theForm) {
labnos = document.frmAdd.elements['labno[]'].length; alert(labnos);
for(i=0; i< labnos; i++) {
alert(document.frmAdd['labno[]'][i].value);
}
}
|
|