Click to See Complete Forum and Search --> : undefined error in checkbox


srimca
04-11-2003, 02:23 AM
<script>
function contactdelete()
{
var checkbox1 = document.contactlist.fordelete;

var t=checkbox1.length;
alert(t);

}
</script>
<html>
<body>
<form name="contactlist">
<input type=checkbox name=fordelete value="1">

<input type=button value=Delete onclick="contactdelete()">
</form>
</body>
</html>

error:

undefined.
the answer should be 1 butit is displaying undefined

gil davis
04-11-2003, 05:34 AM
The only time a checkbox would have a length attribute would be if there were more than one checkbox with the same name. You only have one checkbox, therefore there is no length attribute. Therefore, "document.contactlist.fordelete.length" is undefined.