473,325 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

event confusion

>From what I've read when this is clicked on:

<a href="#" onclick="DoIt()">Some Text</a>

a function defined as:

function DoIt(e) {
if (e) alert("got an event");
}

should work in Mozilla. For IE I'd have to use e=window.event first.

However it doesn't work for me. What *does* work is:

<a href="#" onclick="DoIt(event)">Some Text</a>

The word "event" has to be there. This *doesn't* work:

<a href="#" onclick="DoIt(evt)">Some Text</a>

Is that right? Have I misread the docs?

Here's a simple test program: <http://niof.net/tjs.htm>

--
"The whole aim of practical politics is to keep the populace alarmed --
and hence clamorous to be led to safety--by menacing it with an endless
series of hobgoblins, all of them imaginary." --- H. L. Mencken
Rick Pasotto ri**@niof.net http://www.niof.net
Jul 23 '05 #1
2 1172
Lee
Rick Pasotto said:
From what I've read when this is clicked on:


<a href="#" onclick="DoIt()">Some Text</a>

a function defined as:

function DoIt(e) {
if (e) alert("got an event");
}

should work in Mozilla. For IE I'd have to use e=window.event first.

However it doesn't work for me. What *does* work is:

<a href="#" onclick="DoIt(event)">Some Text</a>

Yes, that is what the documentation says is required.
A parameter named "event" is passed to the event handler.
If you want to be able to see it in your DoIt() function
(which is NOT the event handler function), you need to
pass it as a parameter.

Jul 23 '05 #2
On Thu, 14 Oct 2004 23:19:10 -0500, Rick Pasotto
<ri*********@chi.news.speakeasy.net> wrote:
From what I've read when this is clicked on:

<a href="#" onclick="DoIt()">Some Text</a>

a function defined as:

function DoIt(e) {
if (e) alert("got an event");
}

should work in Mozilla. [...]
No, it won't. You haven't passed any arguments to DoIt(), so e will be
undefined in every browser.
However it doesn't work for me. What *does* work is:

<a href="#" onclick="DoIt(event)">Some Text</a>

The word "event" has to be there. This *doesn't* work:

<a href="#" onclick="DoIt(evt)">Some Text</a>

Is that right? Have I misread the docs?


When you add an intrinsic event as an attribute to a HTML element, the
browser creates an anonymous function that contains your code. In Mozilla
(and some other browsers), this anonymous function has an argument, event,
whilst in IE there is no argument. Consider:

<input ... onclick="myFunction(event);">

Mozilla creates, in effect, this:

inputElement.onclick = function(event) {
myFunction(event);
};

and IE, this:

inputElement.onclick = function() {
myFunction(event);
};

In the first case, it's obvious that myFunction is using the argument
provided by the browser. In the second case, the browser resolves event to
be the global event object.

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Simon Verona | last post by:
I have a usercontrol with code in the "leave" event which updates the final data back into a database. This works fine except if I have a default "accept" button on a form and invoke it by...
4
by: Raj Wall | last post by:
I have an event handler inside a thread class that needs to have access to thread specific information (versus similar info in other threads). If I change the handler's method signature to "public"...
5
by: seal | last post by:
OK, I am trying to fire an event from a usercontrol that tells the page when a checkbox was clicked. Here is the control and when I try and wire up the page to catch the event, my event is not...
7
by: Ron Goral | last post by:
Hello I am new to creating objects in javascript, so please no flames about my coding style. =) I am trying to create an object that will represent a "div" element as a menu. I have written...
2
by: Franky | last post by:
Threre is a Form containing a usercontrol In the form's Load event it references a usercontrol property, say, zz The first showdialog(formx) causes 1 usercontrol_load event 2 form_load event...
13
by: Keith Wilby | last post by:
I've never used this event before and I'm struggling. I have this code in it: If MsgBox("You entered " & Me.cboManagerName _ & " - is this the manager's network logon ID?", vbYesNo, "Confrim...
6
by: TriFuFoos | last post by:
Hi there, I was wondering if anyone knew if/how to assign an event to a global variable? I tried to do it and IE 7 came back with an error saying "Member not found" My code looked similar to...
31
by: Scott M. | last post by:
Am I correct in thinking that because C# doesn't have the "Handles" keyword that VB .NET does, we have to register event delegates manually in C#, whereas in VB .NET using "Handles" takes care of...
2
by: =?Utf-8?B?U2F2dm91bGlkaXMgSW9yZGFuaXM=?= | last post by:
Which is the event sequence when a gridview button (for update) is clicked and the page is post back? I am also a bit confused when to use ..IsPostBack(). If my page data is changing maybe in every...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.