Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Getting keycode from keypress event

Reply
Thread Tools

Getting keycode from keypress event

 
 
yzzzzz
Guest
Posts: n/a
 
      07-13-2003
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.

 
Reply With Quote
 
 
 
 
yzzzzz
Guest
Posts: n/a
 
      07-13-2003
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?

 
Reply With Quote
 
 
 
 
yzzzzz
Guest
Posts: n/a
 
      07-13-2003
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.

 
Reply With Quote
 
Grant Wagner
Guest
Posts: n/a
 
      07-14-2003
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 <>

* 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
keycode or keypress button kkm Javascript 1 10-19-2008 10:45 PM
Determining the Browser and event.keyCode vs. event.which Nathan Sokalski ASP .Net 4 03-11-2006 06:36 AM
Determining the Browser and event.keyCode vs. event.which Nathan Sokalski ASP .Net Building Controls 4 03-11-2006 06:36 AM
"Keycode DLL not found or invalid keycode" Marvin Massih ASP .Net 0 12-31-2004 05:40 PM
event.keyCode Matthias Knöchlein Javascript 3 09-10-2003 12:24 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57