Closed Bug 7997 Opened 26 years ago Closed 25 years ago

[DOM] can't assign event handler to dom-created nodes from JS

Categories

(Core :: DOM: Events, defect, P3)

x86
Linux
defect

Tracking

()

VERIFIED FIXED

People

(Reporter: alecf, Assigned: joki)

References

Details

Attachments

(1 file)

This is on Linux, I haven't tried windows yet. I have code that looks like: var sel = document.createElementWithNameSpace("SELECT", "http://www.w3.org/TR/REC-html40"); . . sel.onchange = myOnChangeHandler; . . divtag.addChild(sel); insertionPoint.addChild(divtag) basically I am: - creating a new select element - adding an onchange handler - adding it to a similarly created DIV tag, then adding that div tag to the DOM tree) this doesn't seem to actually install the handler. If the SELECT element is already in the DOM (i.e. with a <html:select> tag in a XUL file) then I can add the event handler and it works just fine.
Assignee: vidur → joki
This one's for you, Tom.
Status: NEW → ASSIGNED
Summary: can't assign "onchange" handler to dom-created <select> from JS → can't assign event handler to dom-created nodes from JS
Target Milestone: M9
Yeah, this is me. I hadn't caught this case before. Its a more general problem than your test case actually. Modifying summary and accepting.
QA Contact: gerardok → janc
joki at w3c
I just added myself to the cc list and I attached another test. This test maybe a separate bug, Tom you can choose. But I think it is basically demonstrating the same problem and it appears to be related to bug #12849
rods, your bug looks like a problem because the OnLoad() handler isn't firing. If I put <script>Init()</script> in at the bottom, the event handler fires correctly and stuff. Sounds like a necko problem maybe, try handing it to gagan to get off joki's cluttered radar.
Assignee: joki → gagan
Status: ASSIGNED → NEW
Gagan, could you take a look at this?
Assignee: gagan → joki
rods: you should file another bug (against necko) for your problem, which is unrelated to alecf's in this bug. Handing this back to joki (sorry for the noise, Tom).
Moving to M11. Not to hold for M10 per conversation with joki during bug triage today.
Moving multiple bugs to m12
Moving to m13 because Joki seems to be distracted.
Target Milestone: M13 → M14
Mass-moving excess bugs to M14
Target Milestone: M14 → M17
Moving M17.
*** Bug 32400 has been marked as a duplicate of this bug. ***
Blocks: 33577
Adding [DOM] prefix to bugs related to DOM Level 0, 1, or 2 compatibility/compliance.
Status: NEW → ASSIGNED
Summary: can't assign event handler to dom-created nodes from JS → [DOM] can't assign event handler to dom-created nodes from JS
In working on this it seems that this is actually working okay already. The first test case is incomplete but from reconstructing it it the event handler is being added via sel.onchange = myOnChangeHandler; Adding event handlers through function reference like this does indeed seem to work. We don't currently handle adding event handlers through setAttribute or innerHTML but that is covered in 33577. I'm going to mark this fixed. Here is the test case I used for verification. <HTML> <HEAD> </HEAD> <BODY> </BODY> <SCRIPT> function click() { alert('got click'); } var button = document.createElement('BUTTON'); button.onclick = click; button.appendChild(document.createTextNode("click me")); document.body.appendChild(button); </SCRIPT> </HTML>
Status: ASSIGNED → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
Component: DOM Level 1 → DOM Events
QA Contact Update
QA Contact: janc → vladimire
verifying 2001-05-29-09-trunk windows and 2001-05-31-09-trunk linux
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: