Shared publicly  - 
A quiz:

<form><input name=q></form>
form.q == the HTMLInputElement.

<form><input name=q><input name=q></form>
form.q == an HTMLCollection of length 2.

<form><textarea name=q></textarea></form>
form.q == the HTMLTextAreaElement.

<form><input name=q><textarea name=q></textarea></form>
form.q == an HTMLCollection of length 2.

<form><img name=q></form>
form.q == the HTMLImageElement.

So what do you think form.q returns for this?:

<form><input name=q><img name=q></form>

Give your answers in the comments. No cheating!
Katerina Skotalova's profile photoBertine Buchan's profile photoAtte Pulkkinen's profile photoEllie Kesselman's profile photo
HTMLImageElement. (edit) hmm, but should be HTMLCollection of length 2.
HTMLBodyElement because that would be the most awesome.
OOOh, only the form element would be referenced by name, not an image. So its the HTMLInputElement
Must be `HTMLInputElement`, as `HTMLImageElement` is not a form element. And actually I don't get the result in the fifth case.
Given the fifth case, should it be HTMLCollection of length 2?
I guess in the fifth case the JS implementation of the DOM just provides a shortcut, but as soon as there's at least one real form element of the same name, form elements take precedence.
It does indeed return just the HTMLInputElement. This is interoperable across Opera, WebKit, Gecko, and IE (!).

Here's another one.

<form name="x"><img name="y"><input name="y"></form>
document.forms["x"] = 'z'; // renames the input
document.forms["x"] = 'z'; // renames the img
alert(document.forms["x"].y); // what does this alert?

You'd think it'd alert "undefined", right? It does in IE. Not in WebKit/Gecko (which alerts the image) nor in Opera (which alerts the input)...

This weird behaviour is partly specced (there's some weird "remembering the names" thing in the spec) but I have to work out how to make it interact with the weird HTMLImageElement behaviour.
Oh and here's another oddity. What does form.q return for this case?
<form><input name=q type=image><img name=q></form>
I bet its the HTMLImageElement not the input
Yup. type=image inputs, for historical reasons beyond my ken, are blackballed in this API.
Jay C
And this is why, as web developers, we can't have nice things ;)
Also interesting that same trick with <object name="q"> also works by "overriding" img (in other words <form><img name="q"><object name="q"></object></form> will return back object :))
<object> counts as a form control element (because plugins can expose form controls).
Yeah and it's submittable but not resettable too (I wonder how often people use the form control generation via object plug-ins)
I think you are leading me to answer HTMLCollection of length 2 so I'll say HTMLCollection of length 1. (I think I make a big mistake here. lol)
It's amazing that the pile of shit that is the Web platform survives.
Hooray, I got it. I assumed a bug, and I was right!
History: Netscape "classic" did not generate a parse tree, so the document.images, document.forms etc were likely generated by separate code.
+Yuhong Bao That doesn't explain these cases, since these are only about the HTMLFormElement accessors (, not document.forms or document.images.
Actually, tested with NS4 and my explanation is indeed not accurate. It is more likely that NS3 did support accessing images from document.forms (NS4 did), but NS2 did not have document.images or the Image object so in the case of duplicate names between img and input elements, for compatibility the NS2 behavior is maintained.