Getting keycode from keypress event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yzzzzz

    Getting keycode from keypress event

    Hi

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

    function go(event) {
    alert(event.key Code);
    }

    but I always get 0 for the keycode.

    I am using Mozilla.
    Thank you for your help.

  • yzzzzz

    #2
    Re: Getting keycode from keypress event

    Scripsit "yzzzzz":
    [color=blue]
    > Hi
    >
    > I have:
    > <div onkeypress="go( event)">...</div>
    > and:
    >
    > function go(event) {
    > alert(event.key Code);
    > }
    >
    > but I always get 0 for the keycode.
    >
    > I am using Mozilla.
    > Thank you for your help.
    >[/color]
    By the way, it works in IE. Is the property different in Mozilla/Netscape?

    Comment

    • yzzzzz

      #3
      Re: Getting keycode from keypress event

      Scripsit "yzzzzz":
      [color=blue]
      > Scripsit "yzzzzz":
      >[color=green]
      >> Hi
      >>
      >> I have:
      >> <div onkeypress="go( event)">...</div>
      >> and:
      >>
      >> function go(event) {
      >> alert(event.key Code);
      >> }
      >>
      >> but I always get 0 for the keycode.
      >>
      >> I am using Mozilla.
      >> Thank you for your help.
      >>[/color]
      > By the way, it works in IE. Is the property different in Mozilla/Netscape?[/color]

      Ok

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

      Comment

      • Grant Wagner

        #4
        Re: Getting keycode from keypress event

        yzzzzz wrote:
        [color=blue]
        > Scripsit "yzzzzz":
        >[color=green]
        > > Scripsit "yzzzzz":
        > >[color=darkred]
        > >> Hi
        > >>
        > >> I have:
        > >> <div onkeypress="go( event)">...</div>
        > >> and:
        > >>
        > >> function go(event) {
        > >> alert(event.key Code);
        > >> }
        > >>
        > >> but I always get 0 for the keycode.
        > >>
        > >> I am using Mozilla.
        > >> Thank you for your help.
        > >>[/color]
        > > By the way, it works in IE. Is the property different in Mozilla/Netscape?[/color]
        >
        > Ok
        >
        > It's not *keyCode* it's *charCode*.
        > Now *that's* incompatibility .[/color]

        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:
        Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

        />

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

        --
        | Grant Wagner <gwagner@agrico reunited.com>

        * Client-side Javascript and Netscape 4 DOM Reference available at:
        *


        * Internet Explorer DOM Reference available at:
        *
        Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


        * 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


        Comment

        Working...