Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form.checkbox.length

Status
Not open for further replies.

zwrley

Programmer
Aug 7, 2001
14
PH
I was wondering if anyone has encountered this error. When I have more than 1 checkboxes displayed and I try to get its length, I get the number of checkboxes; but if only one checkbox is on the page, I get an "undefined" for the value of length... any help is greatly appreciated!

<html>
<head>
<script>
function showAlert()
{
alert (frm1.chkbox.length)
}
</script>
</head>

<body onload=&quot;showAlert()&quot;>
<form name=frm1>
<input type=checkbox name=chkbox>
<!--
<input type=checkbox name=chkbox>
-->
</form>
</body>
</html>
 
Better to use

var lgn = document.myForm.length;

for(var k = 0; k < lgn; k++){
if(document.myForm[k].type == &quot;checkbox&quot; && document.myForm[k].checked)
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top