Opened 12 years ago

Closed 12 years ago

#2982 closed defect (fixed)

[patch] [cla] dojo.byId fails (IE6,7 Opera) when used on a form, which has a element named/id'd "id"

Reported by: Sam Foster Owned by: Douglas Hays
Priority: high Milestone: 0.9
Component: Core Version: 0.4.2
Keywords: dojo.byId Cc: alex@…; sfoster@…
Blocked By: Blocking:

Description (last modified by bill)

Problem is when you have a form with an element named "id", like:

<form id="foo">
  <input name="id">

and then you do dojo.byId("foo")

the issue can be seen at http://www.sam-i-am.com/work/sandbox/dojo0.4/test_formsById.html

Note, document.getElementById does work here, whereas dojo.byId does not (in IE6,7,Opera)

This may be related to the issue in #2248 (where I've posted the same patch) The patch references ele.attributes.id, instead of ele.id inside the block that provides a workaround for IE/Opera bugs.

The patch has been tested to work/not regress (using the same page above) in IE6, 7, FF1.5, Safari, WebKit?, Opera 9.2

I'd love to get this in 0.4.3 if possible - we'll be on the 0.4 line for a while.

CLA on file as Sam Foster @ Vignette

Attachments (2)

hostenv_browser_byId_changes_sf.patch (887 bytes) - added by guest 12 years ago.
fixes dojo.byId to use ele.attributes.id instead of ele.id
byId.html (1.6 KB) - added by Sam Foster 12 years ago.
test case for the bug (where an element has name="id")

Download all attachments as: .zip

Change History (8)

Changed 12 years ago by guest

fixes dojo.byId to use ele.attributes.id instead of ele.id

comment:1 Changed 12 years ago by guest

  1. Can you attach some example source code to demonstrate the problem? Moreover, the url that you provided results in a Page Not Found error.
  1. That "ele.attributes.id.value" in your patch should be "ele.getAttribute("id")". At least, what happens if "ele.attributes.id" is undefined? Can it be?
  1. I do not understand, how your patch fixes the problem. Why id="id" or name="id" is a problem? What line in hostenv_browser.js produces it and why?

Best regards,
Konstantin Kolinko

comment:2 Changed 12 years ago by guest

Reproduced the problem with dojo 0.9. The page to reproduce the problem is testCase_Form_HiddenFields.htm attached to ticket #2248.

Dojo version:
0.9, built from current development sources of revision 8529.

Browser:
IE6/Windows XP. Does not occur with IE7.


Steps to reproduce:

  1. Open "testCase_Form_HiddenFields.htm"
  2. An alert window shows up with the following message: "undefined"

Expected result:

  1. The message should be "[object]"



Please, disregard my "ele.getAttribute("id")" suggestion from above. It does not work with that test page in IE6. Evaluating

document.getElementById('myForm').getAttribute("id")

there returns the same as

document.getElementById('myForm').id

i.e. an object (a reference to the input field), not a string as were expected. The

document.getElementById('myForm').attributes.id.value

code though works, and returns a string, "myForm", not only in IE6, but also in IE7, Firefox 2.0.

Sorry for inconvenience.

Konstantin Kolinko

comment:3 Changed 12 years ago by Adam Peller

Owner: changed from anonymous to Sam Foster

comment:4 Changed 12 years ago by Sam Foster

Description: modified (diff)
Reporter: changed from guest to Sam Foster

comment:5 Changed 12 years ago by bill

Description: modified (diff)
Milestone: 0.9
Owner: changed from Sam Foster to Douglas Hays
Summary: dojo.byId fails (IE6,7 Opera) when used on a form, which has a element named/id'd "id"[patch] [cla] dojo.byId fails (IE6,7 Opera) when used on a form, which has a element named/id'd "id"

Doug, this is actually a patch to your code from [5739], so can you test/apply if appropriate?

comment:6 Changed 12 years ago by Douglas Hays

Resolution: fixed
Status: newclosed

(In [9831]) Fixes #2982. Changed ele.id to ele.attributes.id.value. Added a testcase for the IE getElementById bug.

Changed 12 years ago by Sam Foster

Attachment: byId.html added

test case for the bug (where an element has name="id")

Note: See TracTickets for help on using tickets.