kaeli said:
Looks like it does. This actually surprises me because I never see it
used (by never, I mean in examples on the web, tutorials, etc) in what I
would think would be a common way - looping through form elements for
validation. I always see stuff like
for (x=0; x<formname.elements.length-1; x++)
Seems to me this would be a lot nicer with
for (var e in document.forms["formname"].elements)
The problem is that you don't know what will be included.
Object properties have a hidden property that says whether they
are enumerable or not. All the properties of Array.prototype, as well
as array lengths, are not enumerable, so doing
for ( var i in arrayRef ) {...}
works. However, in some browsers, the form's elements' "item" property
is enumerable, as are both the named and numbered properties, so
using your code above on the form
<form id="formname" action="">
<input type="text" name="a">
<input type="radio" name="b" value="x1">
<input type="radio" name="b" value="x2">
</form>
will give some of the following properties:
"a", "b", "0", "1", and "2", and a lot more.
Probably not what you had in mind

.
Hmm, let's try:
Opera 7 gives: item, tags, namedItem
Mozilla gives: length, item, namedItem
Netscape 4 gives: a, 0, 1, b, 2, length, name, elements, method,
action, encoding, target
IE 6 gives (brace yourself): language, scrollHeight, isTextEdit,
currentStyle, document, onmouseup, oncontextmenu, isMultiLine,
clientHeight, onrowexit, onbeforepaste, onactivate, scrollLeft,
lang, onmousemove, onmove, onselectstart, parentTextEdit,
oncontrolselect, canHaveHTML, onkeypress, oncut, onrowenter,
onmousedown, onpaste, className, id, onreadystatechange,
onbeforedeactivate, hideFocus, dir, isContentEditable, onkeydown,
clientWidth, onlosecapture, parentElement, ondrag, ondragstart,
oncellchange, recordNumber, onfilterchange, onrowsinserted,
ondatasetcomplete, onmousewheel, ondragenter, onblur, onresizeend,
onerrorupdate, onbeforecopy, ondblclick, scopeName, onkeyup,
onresizestart, onmouseover, onmouseleave, outerText, innerText,
onmoveend, tagName, title, offsetWidth, onresize, contentEditable,
runtimeStyle, filters, ondrop, onpage, onrowsdelete, tagUrn,
offsetLeft, clientTop, style, onfocusout, clientLeft,
ondatasetchanged, canHaveChildren, ondeactivate, isDisabled,
onpropertychange, ondragover, onhelp, ondragend, onbeforeeditfocus,
disabled, onfocus, behaviorUrns, accessKey, onscroll,
onbeforeactivate, onbeforecut, readyState, all, sourceIndex,
onclick, scrollTop, oncopy, onfocusin, tabIndex, onbeforeupdate,
outerHTML, innerHTML, ondataavailable, offsetHeight, onmovestart,
onmouseout, scrollWidth, offsetTop, onmouseenter, onlayoutcomplete,
offsetParent, onafterupdate, ondragleave, children, parentNode,
nodeValue, name, length, onreset, onsubmit, lastChild, elements,
attributes, acceptCharset, action, method, nodeType, target,
previousSibling, ownerDocument, nodeName, childNodes, nextSibling,
firstChild, encoding, a, b, b
(yes, b is there twice!)
IE's result can be explained by it's desing: The form.elements
reference points to the form element itself.
It works wonders for objects you have made yourself, like ones
you use as hash tables.
for (var o in mySelect.options)
Same problem. DOM nodes have no standard saying which properties are
enumerable, and it differes between browsers.
/L