Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get the variable Event 1

Status
Not open for further replies.

seaport

MIS
Jan 5, 2000
923
US
Many sample codes dealing with key stroke event have the first line of code as the following:
Code:
function KeyChecker(evt) {
evt = (evt) ? evt : ((event) ? event : null);
//some other code
}
I would just use
Code:
evt = (evt) ? evt : null

What is the code "(event) ? event : null" for?

My guess is that it is trying to get the variable from the document event rather than the form field event. Am I right?
In Firefox, if I just use "event" directly I will get an error.

Seaport
 
If you expand your example to full if/else statements, you can see what it's doing better.

Lee
 
>What is the code "(event) ? event : null" for?
It is the ie-specific event model. The event object is a global object under the window (omnipresence and optionally implicit). It is equivalent to a clearer (perhaps) version like this.
[tt] evt = (evt) ? evt : ((window.event) ? window.event : null);[/tt]
It is available only during an event on ie. Hence, the line check the implementation of event object (under window), if yes, re-assign evt to window.event. As such, cross-browser script is becoming possible using the same variable named evt even the content of it maybe very much different, moz vs ie.
 
By the way, tsuji, is there any rule about the position of the event parameter when defining a function in the Netscape event model?

For example, if the function to call requires 1 event variable - e, and 2 other variables. a and b, do I have to put the e as the last variable like

function testA(a,b,e)
{
//codes
}

or it does not matter at all?

Seaport
 
Tacitly and in practice, it is usually the last. In case of no ambiguity, I would say at any position.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top