Getting keycode from keypress event

Y

yzzzzz

Hi

I have:
<div onkeypress="go(event)">...</div>
and:

function go(event) {
alert(event.keyCode);
}

but I always get 0 for the keycode.

I am using Mozilla.
Thank you for your help.
 
Y

yzzzzz

Scripsit "yzzzzz":
Hi

I have:
<div onkeypress="go(event)">...</div>
and:

function go(event) {
alert(event.keyCode);
}

but I always get 0 for the keycode.

I am using Mozilla.
Thank you for your help.
By the way, it works in IE. Is the property different in Mozilla/Netscape?
 
Y

yzzzzz

Scripsit "yzzzzz":
Scripsit "yzzzzz":

By the way, it works in IE. Is the property different in Mozilla/Netscape?

Ok

It's not *keyCode* it's *charCode*.
Now *that's* incompatibility.
 
G

Grant Wagner

yzzzzz said:
Scripsit "yzzzzz":


Ok

It's not *keyCode* it's *charCode*.
Now *that's* incompatibility.

The way events are handled and the properties they have are different between IE
and Mozilla.

IE has a global Event object attached to the default window object
(window.event). In Mozilla, the event is passed as the first parameter to the
event handler.

A list of event object properties in IE is available at: <url:
http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_event.asp
/>

A list of event object properties in Mozilla is available at:
<url: http://www.mozilla.org/docs/dom/domref/dom_event_ref.html#999092 />

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top