Hi, I need to get event handler's argument in Firefox3 - but it does not have any global 'event' variable like IE nor it passes an argument to the handler. How do I get this argument then???

function doSomething(e)
{
     if(!e) var e = event; //for IE
     alert(e); //It shows 'undefined' in Firefox 3, WHY?
}
....
<a href='#' onmouseout='doSomething();'>

I doubt the above code would even work in FF2 considering that you explicitly need to pass the event when registering the handler.

<a href="#" onclick="doSomething(event);">

WOW! thanks! I thought it is passed automatically and didn't knew that I have 'event' variable available in FF

Thanks again!

Netscape method was always a pain compared to ie's elegant intuitive method. So this simple intelligible ie code will suffice for all ie only applications:
1.

<a href="#" onclick="doSomething();">doSomething</a>

<script>
function doSomething(){
    alert(event.type)
   }
</script>

On the other hand Netscape and its countless breeds will always require its arbitrary unintelligible awkward oldfashion method from the time when code was not separated from content:
2.

<a href="#" onclick="doSomething(event);">doSomething</a>

<script>
function doSomething(e){
    alert(e.type)
   }
</script>

...passing the event-object as a function-argument which by the way is additionally inefficient, especially because you will have to go back to html code in casse you didn't predict that you'll be needing to check for event type during your script developement!

A Myth
On the other hand if the coder has supplied the argument correctly, the bad use of "if(!e) e = event" conditional and assignment to "e" var is absolutely NOT required for the function to be cross browser compatible. IE understands the oldfashion way perfectly.

It's a false reqiurement and a very bad coding habit introduced by Netscape coders to irritate peaking and sniffing youngsters who know nothing about coding to make them falsely come to the conclusion that it is Explorer who requires more bull code in order to make a simple function work. While (as you can see from these explicitly clear examples), it was always Netscape and its malicious breed who are not ready to give up their old inefficient unintelligible abstract and unexpected methods away anyway.

So,
This will work correctly in all without a need for any kind of additional conditionals or event assignments to vars:
3.

<a href="#" onclick="doSomething(event);">a href</a>

<script>
function doSomething(e){
    alert(e.type)
   }
</script>

My best regads @all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.