X
X
Xored2011-11-28 08:39:15
JavaScript
Xored, 2011-11-28 08:39:15

Event target in Firefox

Good afternoon!

There is a function:
function changeHandler(e) {
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target; else if (e.srcElement) targ = e.srcElement;
alert(targ.type);
}

It hangs on input events: onchange='changeHandler()' onkeyup='changeHandler()'
In IE and Chrome, everything works as intended, an alert pops up with the type of the triggered event. But in Firefox e and, accordingly, targ is always undefined. What could be the reason for this and how to properly get the event object in FF?

Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anatoly, 2011-11-28
@Xored

onchange='changeHandler(event)' onkeyup='changeHandler(event)' - so try

S
sefus, 2011-11-28
@sefus

stackoverflow.com/questions/4581976/window-event-srcelement-not-working-in-firefox

S
Sererator, 2012-01-05
@Serator

input: onchange='changeHandler()' onkeyup='changeHandler()' - in this code you do not pass "e" (event), but in "function changeHandler(e) {" you request it.
It should be like this:
input: onchange='changeHandler(e)' onkeyup='changeHandler(e)'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question