Compatability Between IE and Netscape (Event Property?)

R

Ron D

What is the equivalent of

if (window.event.srcElement.id == "txt1ST_INIT_NM")

in Netscape?
 
D

DU

Ron said:
What is the equivalent of

if (window.event.srcElement.id == "txt1ST_INIT_NM")

in Netscape?

if(evt.target.id == "txt1ST_INIT_NM")
in NS 6+, Mozilla-based browsers, in Opera 7.x and in all other W3C DOM
2 Events compliant browsers.

We would also need to see your code, script function to implement an
event listener. Also, depending on your code (capture mode or bubbling
up) and how complex it is, you might be forced to use
evt.currentTarget.id instead.
It's impossible to say more without being able to actually examine your
whole code.

DU
 
L

Lasse Reichstein Nielsen

What is the equivalent of

if (window.event.srcElement.id == "txt1ST_INIT_NM")

in Netscape?

In Netscape 6+ (and other W3C DOM 3 Events compliant browsers, as well
as in Nescape 4) the event object is an argument to the event handler
function. In IE, it is a global variabled called "event". So, there is
no direct substitute for the above, because you have to add an argument
to the handler function.

I usually start my handlers with :

function (evt) {
evt = evt || window.event; // IE sucks!

Further, the "srcElement" is Microsoft's invention, where the W3C DOM
calls it "target". So I usually follow up with:

var tgt = evt.target || evt.srcElement; // IE sucks!

From here, you can just write:

if (tgt.id == "txt1ST_INIT_NM") ...

Good luck.

/L 'yes, I write the comments every time too'
 

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,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top