Closed
Bug 154447
Opened 22 years ago
Closed 22 years ago
document.element defaults to the 'name' attribute instead of the 'id' attribute
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
WONTFIX
People
(Reporter: dan_smeltz, Assigned: jst)
Details
From Bugzilla Helper: User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.0) Gecko/20020530 BuildID: 2002053012 When trying to access the 'form' element via the document.formid syntax, the script does not find the element if there is a colon (:) in the form name. The form id being used matches the id on the 'form' tag, but the name contains a colon (:). Reproducible: Always Steps to Reproduce: 1. Please view the sample HTML/Javascript below <html> <body> <script language="javascript"> <!-- function __doPostBack(eventTarget, eventArgument) { var theform = document.frmMain_frmMain; theform.submit(); } // --> </script> <form id="frmMain_frmMain" name="frmMain:frmMain" method="post" action="" language="javascript" enctype="multipart/form-data"> <input id="frmMain__ctl0__ctl1_cbxTest" type="checkbox" name="frmMain:_ctl0:_ctl1:cbxTest" onclick="__doPostBack('frmMain:_ctl0:_ctl1:cbxTest','')" language="javascript" checked=true /> </form> </body> </html> *** The above code does not work. If you change the colon in the name attribute, of the form tag, to an underscore, then this code will work.
Comment 1•22 years ago
|
||
This bug is invalid for two reasons:
1. In JavaScript, colons are not allowed in variable names. This is
true in IE as well as in Mozilla. The reason is, colons are special
symbols that the JS parser looks for, denoting "labels" in the code.
To see it generates an error, copy the first javascript:URL below
and hit <Enter> in any browser. Then copy the second one and <Enter>:
javascript: void(window.onerror = function(e) {alert('ERROR: ' + e)});
javascript: var a:b = 1;
Maybe the DOM allows colons in HTML names; I don't know. But in
JavaScript, colons are a no-no in any identifier -
2. The |document.formid| syntax that you refer to is IE-only.
What works across all browsers is |document.formname|. So in your
example above, when you do |var theform = document.frmMain_frmMain;|,
this works in IE because IE syntax accepts |document.formid| syntax.
> If you change the colon in the name attribute of the form tag,
> to an underscore, then this code will work.
b. That's because the identifier you're using in the function,
|frmMain_frmMain|, is now a formname! So Mozilla (and all
browsers) can successfully resolve |document.frmMain_frmMain|,
because they all can resolve |document.formname|.
Have to mark this one invalid, sorry -
Status: UNCONFIRMED → RESOLVED
Closed: 22 years ago
Resolution: --- → INVALID
Comment 2•22 years ago
|
||
Marking Verified - See bug 154072, "Site uses proprietary IE-only DOM syntax", where the same issue came up. That bug is assigned to the Evangelism component, which will try to contact the site listed there and advocate W3C-compliant HTML.
Status: RESOLVED → VERIFIED
Reporter | ||
Updated•22 years ago
|
Status: VERIFIED → UNCONFIRMED
Resolution: INVALID → ---
Reporter | ||
Comment 3•22 years ago
|
||
This is from the HTML 4.01 spec. According to the W3C, the name attribute is only for backward compatibility. Please see quote below: name = cdata [CI] This attribute names the element so that it may be referred to from style sheets or scripts. Note. This attribute has been included for backwards compatibility. Applications should use the id attribute to identify elements.
Comment 4•22 years ago
|
||
OK, reassigning to the DOM experts -
Assignee: rogerl → jst
Component: JavaScript Engine → DOM Level 0
QA Contact: pschwartau → desale
Updated•22 years ago
|
Status: UNCONFIRMED → NEW
Ever confirmed: true
Assignee | ||
Comment 5•22 years ago
|
||
document.foo is also only for backwards compatiblity, so arguing that document.foo should resolve to something other than what it used to resolve to based on arguments that themselves are about backwards compatibility only is not enough for us to change how mozilla works. If you use ID attributes, then document.getElementById('my_id') will do what you want, it's straight forward, clean, and it's obvious what the code does by looking at the code. WONTFIX.
Status: NEW → RESOLVED
Closed: 22 years ago → 22 years ago
Resolution: --- → WONTFIX
You need to log in
before you can comment on or make changes to this bug.
Description
•