SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Capturing keypress for arrows and pg up/pg dn

    Hey all.

    I'm capturing the keypress and taking action on it and it works fine for the tab key and enter key, but the pg up/pg dn and the arrow keys are not registering.

    I'm using the following commands:

    document.onkeypress = stopRKey;
    document.getElementById("ordersList").onkeypress = stopRKey;

    stopRKey is a JS function that I copied, it evaluates the keypress.

    How do I capture the pg up/dn and arrow keys?

  2. #2
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Webspeeder View Post
    Hey all.

    I'm capturing the keypress and taking action on it and it works fine for the tab key and enter key, but the pg up/pg dn and the arrow keys are not registering.

    I'm using the following commands:

    document.onkeypress = stopRKey;
    document.getElementById("ordersList").onkeypress = stopRKey;

    stopRKey is a JS function that I copied, it evaluates the keypress.

    How do I capture the pg up/dn and arrow keys?
    Actually, on the document I can get the keys to register, so my question is how do I get them to register on the contents of a <div> element?

    I have a table of data being displayed inside the <div> and I want to take action when those keys are pressed.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,700
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    You'll need to capture it with keyup or keydown, because IE doesn't fire the keypress event for pageup/pagedown

    Quirksmode - Detecting Keystrokes
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    You'll need to capture it with keyup or keydown, because IE doesn't fire the keypress event for pageup/pagedown

    Quirksmode - Detecting Keystrokes
    Actually, I'm in Firefox in this test. The onkeypress works, just not inside the <div>.

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,700
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    If you simplify the html code down to some sample code for posting here that still exhibits the trouble, that can help us to duplicate the trouble you're facing so that we can craft together a solution for you.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    If you simplify the html code down to some sample code for posting here that still exibits the trouble, that can help us to duplicate the trouble you're facing so that we can craft together a solution for you.
    I inserted onkeydown and that works for both IE and FF. I had onkeypress and thought that each had their own, but FF goes both ways.

    Thank you for the tip.


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
  •