By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,230 Members | 2,425 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,230 IT Pros & Developers. It's quick & easy.

Getting keycode from keypress event

P: n/a
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.

Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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?

Jul 20 '05 #2

P: n/a
Scripsit "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?


Ok

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

Jul 20 '05 #3

P: n/a
yzzzzz wrote:
Scripsit "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?


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/a.../obj_event.asp
/>

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

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.