AJAX: responsetext versus responsexml when using eventhandlers, IE-problem

P

Pugi!

Currently I am using a responsexml for an xmlhttprequest. The
information is then processed by javascript : elements are created with
attributes incl events using setAttribute; in other words I create html
with the information in the responsexml. This works fine with firefox
and Opera, but IE doesn't do anything with these events (onclick,
onmouseover, ...) on an image or cell (td) created this way. One
alternative is that I should be able to identify the elements who need
a specific event and then launch a javascript function that adds the
desired event to the tags.
for (var i = 0; i < arrElements.length; i++) {
arrElements.onclick = doSomething;
}
The other alternative is that instead of xml I created text (html) on
the serverside and use a responsetext.

I think the second one is the best alternative ?
Or are there other options ?

Pugi!
 
M

Martin Honnen

Pugi! said:
Currently I am using a responsexml for an xmlhttprequest. The
information is then processed by javascript : elements are created with
attributes incl events using setAttribute; in other words I create html
with the information in the responsexml. This works fine with firefox
and Opera, but IE doesn't do anything with these events (onclick,
onmouseover, ...) on an image or cell (td) created this way. One
alternative is that I should be able to identify the elements who need
a specific event and then launch a javascript function that adds the
desired event to the tags.
for (var i = 0; i < arrElements.length; i++) {
arrElements.onclick = doSomething;
}


The problem is not with responseText or responseXML, the problem is with
setAttribute in IE scripting HTML. Don't use that, setAttribute in IE is
broken compared to the way it works in other browsers following the W3C
DOM Core specification. You can always use element properties e.g.
element.onclick or element.onmouseover and assign a function directly,
that works cross browser.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,268
Latest member
AshliMacin

Latest Threads

Top