473,500 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to call event as a function in mozilla

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
3 10183
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
AJAXAvatar
2 New Member
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
wildthing4ever
3 New Member
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
39673
by: yzzzzz | last post by:
Hi I have: <div onkeypress="go(event)">...</div> and: function go(event) { alert(event.keyCode); }
5
20755
by: Jeff Thies | last post by:
I have this IE specific bit of code for finding the originating node: var obj=window.event.srcElement; How do I do that cross browser (Opera, NS, Safari...)? Is there a standard DOM method? ...
2
1586
by: JeeWee | last post by:
Hi all, I'm looking for a way to "bind" multiple eventhandler function to the same event. In other languages this can often be done by using the += operator, unfortunately this doesn't seem to...
3
4669
by: Vikram Bhatia | last post by:
1. Is there an event to capture scrolling using mouse wheel in Netscape 6.x? 2. When arrow keys are used to scroll a page in Netscape 6.x, the scrolling offsets obtained using...
3
13050
by: Lachlan Hunt | last post by:
Hi, I've been looking up lots of documentation and trying to work out a cross-platform method of capturing a keyboard event and working out which key was pressed. From what I can find, there...
39
6475
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
10
23252
by: Noozer | last post by:
Is it possible to detect where on a page the click occurred when the OnClick event of the BODY tag is fired? Thx
15
21324
by: prabhdeep | last post by:
Hi, Can somebody explain, why in following code, i get "event not defined" error funcTest(sMenu) { doument.getElementById('id1').addEventListener('mousedown', function(){ click(sMenu,...
1
1591
by: finerrecliner | last post by:
what i'm trying to accomplish: user clicks button. then can click 2 more times anywhere on the page and display his mouse coordinates. after those 2 clicks, go back to normal mouse behavior the...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.