Click to See Complete Forum and Search --> : window.event information


khayman2001
12-14-2003, 02:28 PM
I've been racking my searching capabilites, and I can't find any information on what the window.event object is, or how to use it. Any help? :confused:

fredmv
12-14-2003, 02:32 PM
That property is specific to IE — in Mozilla/Netscape the Event object is passed as the first argument to the event handler's function. If you're wondering what it is, it simply keeps information about what events are occuring as its name implies. You may be interested in this article (http://www.wdvl.com/Authoring/JavaScript/Events/event_object.html) for more information.

khayman2001
12-14-2003, 02:51 PM
Thanks a bunch! :D :cool:

fredmv
12-14-2003, 02:52 PM
You're very welcome. If you need any further clarification, please feel free to ask. :D

evnafets
02-26-2004, 07:06 AM
Originally posted by fredmv
That property is specific to IE — in Mozilla/Netscape the Event object is passed as the first argument to the event handler's function. If you're wondering what it is, it simply keeps information about what events are occuring as its name implies. You may be interested in this article (http://www.wdvl.com/Authoring/JavaScript/Events/event_object.html) for more information.

Can someone please confirm if this is still true? I am trying to pickup the keyPress event in a textfield. I have the following (simple) example.
The event is firing, as I get the alert boxes.
My problem is that I can't seem to get a handle on the event object. The parameter passed to this method is void/null. The second alert just shows "undefined"
I am using Mozilla 1.5, Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007


<html>
<head>
<script language="javascript" >
<!--
function check(evnt)
{
alert("A key was pressed!");
alert(evnt);
}
//-->
</script>
</head>
<body>
<form name="myform" method="post" >
Test <input type="text" onkeyPress="check();">
</form>
</body>
</html>

Cheers,
evnafets

fredmv
02-26-2004, 07:07 AM
Welcome to the forums.

How exactly do you want it to work?

evnafets
02-26-2004, 07:16 AM
Thanks.

Basically I am just wanting to find out which key was pressed.
I was pretty sure it would be either
event.keyCode (like IE) or event.which (from old netscape javascript reference)
However I am not even able to get the event object, let alone its info.

fredmv
02-26-2004, 07:42 AM
http://www.din.or.jp/~hagi3/JavaScript/JSTips/Mozilla/Samples/KeyEvent.htm

evnafets
02-26-2004, 08:27 AM
Thanks for that. I've looked through the example and got a similar one working on my page.

To get it to work I removed the onclick event from the declaration of the textfield and instead assigned it to the textfield in the init method using the following:

<input type="text" name="myTest">
in the init method:
document.myForm.myTest.onkeypress = check;

The event then fired correctly, and also passed the event object as a parameter I would have preferred declaring the event as part of the textfield declaration, but if this is the way it has to be...

Thanks again,
evnafets