Getting keycode from keypress event

Discussion in 'Javascript' started by yzzzzz, Jul 13, 2003.

  1. yzzzzz

    yzzzzz Guest

    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.
    yzzzzz, Jul 13, 2003
    #1
    1. Advertising

  2. yzzzzz

    yzzzzz Guest

    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?
    yzzzzz, Jul 13, 2003
    #2
    1. Advertising

  3. yzzzzz

    yzzzzz Guest

    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.
    yzzzzz, Jul 13, 2003
    #3
  4. yzzzzz

    Grant Wagner Guest

    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/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 <>

    * 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
    Grant Wagner, Jul 14, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin Massih

    "Keycode DLL not found or invalid keycode"

    Marvin Massih, Dec 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,120
    Marvin Massih
    Dec 31, 2004
  2. Nathan Sokalski
    Replies:
    4
    Views:
    4,138
    Nathan Sokalski
    Mar 11, 2006
  3. Nathan Sokalski

    Determining the Browser and event.keyCode vs. event.which

    Nathan Sokalski, Mar 10, 2006, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    164
    Nathan Sokalski
    Mar 11, 2006
  4. Matthias Knöchlein

    event.keyCode

    Matthias Knöchlein, Sep 10, 2003, in forum: Javascript
    Replies:
    3
    Views:
    138
    Janwillem Borleffs
    Sep 10, 2003
  5. kkm

    keycode or keypress button

    kkm, Oct 19, 2008, in forum: Javascript
    Replies:
    1
    Views:
    83
Loading...

Share This Page