www.webdeveloper.com
Results 1 to 11 of 11

Thread: Strange onkeypress event with ESC in Firefox...

Threaded View

  1. #1
    Join Date
    Jan 2008
    Location
    ncl,uk
    Posts
    56

    Question Strange onkeypress event with ESC in Firefox...

    Hi all,
    I have the following code:

    <input onkeydown="return testKey(event)" type="text"/>
    function testKey(evt)
    {
    var charCode = (evt.which) ? evt.which : event.keyCode;
    alert(charCode)
    }

    - This code works perfectly in IE with no errors
    - In Firefox (Using FireBug to check for JS errors) the code alerts every character fine except for 1 key which is the ESC key. When i press the ESC key in that input field FireBug throws an error saying: "event is not defined". So for some retarded reason Firefox is looking at the event.keyCode part (which is supposed to be used for IE only) for only the ESC key (all other keys dont throw up an error).

    EDIT: Ok i have figured out why its happening now, because Firefox charCode returns 0 and IE returns undefined and when you do 0 || undefined it returns undefined which i didnt think would be the case. Anyone have an idea how to get around the ESC key besides detecting for 0 and undefined?
    Last edited by sekter; 05-14-2010 at 05:58 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles