Browser inconsistencies in implementing name getters on forms and form element collections

Consider the following testcase:

   <!DOCTYPE html>
   <form name="x">
     <img name="y">
   </form>
   <script>
     alert(document.forms["x"].y);
     alert(document.forms["x"].elements.y);
   </script>

The results are as follows:

IE9: alerts undefined twice (in both standards and quirks mode
      as far as I can tell).
Opera 11: alerts [object HTMLImageElement], then undefined
Firefox: alerts [object HTMLImageElement], then undefined
Chrome: alerts [object HTMLImageElement] twice
Safari: alerts [object HTMLImageElement] twice

Chrome and Safari are consistent with what the spec currently says for 
the namegetter on HTMLFormElement, but not with the behavior specified 
for form.elements.

Opera and Firefox do what the spec currently says for form.elements, but 
not for HTMLFormElement.

IE currently does what the spec currently says.

I'm pretty sure I've seen code in the past that switches on "IE vs 
Netscape" and uses form.x for the latter while using getElementById for 
the former, but that was a good long while ago.  So I think we're 
willing to risk the compat hit in Gecko of changing to the currently 
specced behavior (which will incidentaly be simpler than what we do 
now).  Are Opera and WebKit willing to do that too?  Or does the spec 
need to change?

-Boris

Received on Thursday, 14 April 2011 13:46:52 UTC