nickfox
09-19-2006, 02:02 AM
I am trying to create a set of checkboxes. If I create 2 checkboxes in the following code. I get a length of 2 from the statement:
document.theform.mycheckbox.length
If I remove the second createElement and only create one, I get undefined instead of document.theform.mycheckbox.length = 1.
why don't I get 1?
thanks
Nick
<html><head><title></title>
<script type="text/javascript">
function load () {
var theform = document.getElementById('theform');
var el = document.createElement('input');
el.type = 'checkbox';
el.id = 'mycheckbox';
el.name = 'mycheckbox';
el.value = 'mycheckboxvalue';
theform.appendChild(el);
// REMOVE THIS SECOND ELEMENT
var el2 = document.createElement('input');
el2.type = 'checkbox';
el2.id = 'mycheckbox';
el2.name = 'mycheckbox';
el2.value = 'mycheckboxvalue2';
theform.appendChild(el2);
if (document.theform.mycheckbox) {
document.body.innerHTML += 'document.theform.firstChild.id: ' + document.theform.firstChild.id + '<br>';
document.body.innerHTML += 'document.theform.mycheckbox.length: ' + document.theform.mycheckbox.length + '<br>';
}
}
</script>
</head>
<body onload="load()">
<form id="theform" name="theform"></form>
</body></html>
document.theform.mycheckbox.length
If I remove the second createElement and only create one, I get undefined instead of document.theform.mycheckbox.length = 1.
why don't I get 1?
thanks
Nick
<html><head><title></title>
<script type="text/javascript">
function load () {
var theform = document.getElementById('theform');
var el = document.createElement('input');
el.type = 'checkbox';
el.id = 'mycheckbox';
el.name = 'mycheckbox';
el.value = 'mycheckboxvalue';
theform.appendChild(el);
// REMOVE THIS SECOND ELEMENT
var el2 = document.createElement('input');
el2.type = 'checkbox';
el2.id = 'mycheckbox';
el2.name = 'mycheckbox';
el2.value = 'mycheckboxvalue2';
theform.appendChild(el2);
if (document.theform.mycheckbox) {
document.body.innerHTML += 'document.theform.firstChild.id: ' + document.theform.firstChild.id + '<br>';
document.body.innerHTML += 'document.theform.mycheckbox.length: ' + document.theform.mycheckbox.length + '<br>';
}
}
</script>
</head>
<body onload="load()">
<form id="theform" name="theform"></form>
</body></html>