Closed Bug 249558 Opened 21 years ago Closed 21 years ago

Elements with id="document" cause document.* JavaScript functions to stop working.

Categories

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

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: arend, Unassigned)

Details

Attachments

(1 file)

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040614 Firefox/0.9 Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040614 Firefox/0.9 If I declare an HTML element with id="document", like <input id="document"/> this will cause document.* JavaScript functions, like document.getElementById() to stop working. It will result in an error saying "Error: document.getElementById is not a function". Probably the "document" id just overwrites the JavaScript "document" keyword. The bug is in both Mozilla 1.7 and Firefox 0.9. I also tried to do this with Konqueror, which does not have the problem. Reproducible: Always Steps to Reproduce: 1. Take the following example code: <html> <head></head> <body> <form method="post" action="http://127.0.0.1/index.php"> <p>Add a new link ...</p> <p><input type="radio" id="external" name="doctype" value="external" checked="checked" onclick="document.getElementById('next').value = 'Finish';"/>to this external URL: <input type="text" name="url" id="url" value="http://" onclick="document.getElementById('external').checked = true; document.getElementById('next').value = 'Finish';"/></p> <p><input type="radio" id="document" name="doctype" value="document" onclick="document.getElementById('next').value = 'Next';"/>to an internal document</p> <p><input type="submit" name="button" id="next" value="Finish"/> <input type="submit" name="button" value="Cancel"/> </body> </html> 2. Now click the different radio buttons. Actual Results: You will see none of the JavaScript is working and on the JavaScript console the message "Error: document.getElementById is not a function" will appear. Expected Results: If a different radio button is selected it should change the text on the Finish button and if the text field is clicked, the first radio button should be selected.
I can see the js error happening, using: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8a2) Gecko/20040701 Firefox/0.8.0+ The js error only happens when the checkbox is inside a form element.
AFAIK document.* would here refer to form.document.*. Anyway the question is if a form should be allowed to replace this.
Absolutely. "document" on its own just looks up the scope chain; if it finds a "document" property on the document object, it will just use that. If you want to ensure you get window.document, then you should call it window.document, not plain document. This looks invalid to me.
As long as nothing in the scope chain declares a window property, then window won't be the global object which is what you want. Not much we can do about this, this is just how JS works...
Marking INVALID.
Status: UNCONFIRMED → RESOLVED
Closed: 21 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: