By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,382 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,382 IT Pros & Developers. It's quick & easy.

How to call event as a function in mozilla

P: n/a
I have a function that is used as an event for some parts of the
script.
i.e.
function somethind(e) {
if (!e.currentTarget.documentElement ){
...
}
}

I need to call this function manually (not by assigning it to an
event) Yet I cannot seem to deal with 'e'.
If I call it as: something(e); I get a 'not defined', if I ommit it I
get an undefined.
For some reason 'e' is undefined in the calling script. What decides
when it is available as an event object? and how can I resolve this
issue?

Thanks
Joshua
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
cy*********@yifan.net (Jadow) writes:
I have a function that is used as an event for some parts of the
script.
It is an event handler. The "e" will be the event then.
function somethind(e) {
if (!e.currentTarget.documentElement ){
...
}
}
That requires the currentTarget property to be a document object.
I need to call this function manually (not by assigning it to an
event) Yet I cannot seem to deal with 'e'.
If I call it as: something(e); I get a 'not defined', if I ommit it I
get an undefined.
If you write
something(e);
and "e" is not a defined variable, then it is ofcourse an error. You have
to add an event as argument (or any object with a currentTarget property).
Try
something({currentTarget:document});
For some reason 'e' is undefined in the calling script.
That reason is proabably that it hasn't been defined.
What decides when it is available as an event object?


When you assign it. The "e" in the function definition only
exists inside the function. It is a local name for the argument
to the function.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: 2
There's an article here entitled "Firefox: 'event is not defined'" that explains exactly why this happens and how to fix it (so it works in both IE and Mozilla):

http://www.theblueform.com/Home/TheMakingOf.aspx

Well worth a read to understand why it happens. Lots of other good JavaScript advice here too.
Jul 3 '06 #3

P: 3
Hi,

I was using the command: event.srcElement.value = ""; in a js function which function perfectly in IE. The function was called on the onchange event of a textbox.

I read the article you'd mentioned, but didn't quite understand how to apply it in this case. Can you help me out? Let's say this is the code:

...
<input type="text" id="abc" onchange="return test();">
...

<script language="javascript">
function test()
{
event.srcElement.value = "";
}
</script>
(Works in IE, gives an error (event not defined) in Firefox)
Jul 15 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.