SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onkeyup event handler

    Hi,

    Im using onKeyUp on a text input field and everytime some information is gathered from a database through ajax.

    Is there anyway to cancel onKeyUp events that are within X seconds of the previous event trigger? I dont want to use setTimeout because i dont want them called at all.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cancel onKeyUp events
    In IE (for one), you can't cancel onkeyup events. You can cancel onkeydown and onkeypress events, to effectively stop the user from typing.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can cancel onkeydown and onkeypress events
    How is this done?

    to effectively stop the user from typing.
    I am not really wanting to stop the user from typing. I just dont want to run the database lookup function im running onkeyup for every keyup, but rather only onkeyup per X seconds that is pressed.

  4. #4
    I'm not a human
    Join Date
    Aug 2006
    Location
    India
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    i think u may be thinking of using ajax for something like a searching box or else

    if u r intending to display names when a letter is pressed.., i think it won't be problem to fetch data from the tables using ajax.

    can i know what is the real need of restricting the user from typing???
    Regards,
    Vijay
    Follow me on twitter @vijaycbe
    World Holiday Calander || My Cricket Blog

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I see what you mean,

    Yes you can put a check into your code to only allow a lookup to happen if the last keypress was 2 seconds or more ago, but you'll still be stuck with using a timeout under some situations, consider:

    - user wants to type in the word "english"
    - user types "e", lookup occurs on "e"
    - user types "n" "g" within 2 seconds, nothing happens
    - user types "l" - lookup occurs on "engl"
    - user types "i" "s" "h" within 2 seconds, nothing happens
    - user waits
    - and waits
    - etc

    you might want to consider something like:
    - user presses a key
    - is there an incomplete ajax request happening? if so, abort it.
    - start a new request


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
  •