SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Firefox 1.0 bug alert: onkeypress onkeydown

    Hi,

    I tracked down some strange behaviour in FF1.0, and I thought I'd post it in case it might help someone else avoid some frustration.

    In FF1.0, in order to find the key code in response to the 'onkeypress' event, you have to use 'e.which' (which quirksmode.com says is an old NN4 property)--'e.keyCode' returns 0 for me. On the other hand, for the 'onkeydown' event, you can get the key code with e.keyCode--and 'e.which' also works.

    Here's some code showing what I mean:
    Code:
    <html>
    <head>
    <script type="text/javascript" language="javascript">
    <!-- Hide from browsers without javascript
    
    window.onload=function()
    {
    	var tb = document.forms["f"].elements[0];
    	//tb.onkeydown = test_keycode;
    	tb.onkeypress= test_keycode;
    
    	tb.focus();
    };
    
    function test_keycode(e)
    {
    	if(!e) var e = window.event;
    	if(e.which) alert("e.which: " + e.which);
    	if(e.keyCode) alert("e.keyCode: " + e.keyCode);
    }
    
    // End hiding -->
    </script>
    </head>
    <body>
    
    <form name="f" method="post" action="">
        <input type="text" name="tb0" />
    </form>
    
    </body>
    </html>
    Last edited by 7stud; Dec 2, 2004 at 08:34.

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good on ya

    Also for reference.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A year old???!! ppk, ppk, update your website!


  4. #4
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mozilla has done this since ages,
    http://www.mozilla.org/editor/key-event-spec.html


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •