Closed Bug 423627 Opened 18 years ago Closed 15 years ago

Wrong javascript retrieval with call: document.forms[0].elements['length']

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: manseeverard, Unassigned)

Details

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12 When a javascript like the follow is executed in firefox, instead of retrieval the correct 'length' input type element, it get the length of the elements in the form (like document.form[0].elements.length). The following example works fine in IE and Opera, but it wrong in Firefox: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>test</title> <script language="javascript"> function displayLength() { var formElem = document.forms['formname'].elements['length']; alert(formElem); } </script> </head> <body> <form name="formname" action="formaction"> <input name="length" value="10" type="text"> <input onclick="displayLength();" type="button" name="click me"> </form> </body> </html> Reproducible: Always Steps to Reproduce: 1.write the example to an html file 2.open the file with firefox and click on the button to see that it does not work 3.open with IE or Opera and click on the button to see that it work Actual Results: The call document.forms['formname'].elements['length'] return the value of document.forms['formname'].elements.length Expected Results: The call document.forms['formname'].elements['length'] MUST return the html element: <input name="length" value="10" type="text">
Component: Error Console → DOM
Product: Firefox → Core
QA Contact: error.console → general
I think the length property is defined as readonly: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75708506 It would be a good idea to decide on a strategy for what to do in these edge cases. The intent of readonly properties is that the value should not be replaced. I think this should also apply to methods. The authors of the DOM spec did not ever make a method readonly, and probably did not consider that a method could be deleted or replaced by the user.
Neither HTMLFormControlsCollection nor HTMLCollection has an OverrideBuiltins extended attribute, so length should be the actual length.
Status: UNCONFIRMED → RESOLVED
Closed: 15 years ago
Hardware: x86 → All
Resolution: --- → INVALID
Version: unspecified → Trunk
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.