text area key capture

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

    text area key capture

    I'm a javascript newbie. How can I can I check user input using the keypress
    or keydown events prior to it being displayed in the textbox? What I want
    to be able to do is to check the keycode to against a pre-determined string
    to see if the key is valid input? If it is not it won't be displayed in the
    textbox.

    Thanks,
    Jim


  • Lee

    #2
    Re: text area key capture

    JimO said:[color=blue]
    >
    >I'm a javascript newbie. How can I can I check user input using the keypress
    >or keydown events prior to it being displayed in the textbox? What I want
    >to be able to do is to check the keycode to against a pre-determined string
    >to see if the key is valid input? If it is not it won't be displayed in the
    >textbox.[/color]

    It's generally better to wait until they finish typing, and then
    check for invalid characters. If you block characters, you open
    yourself up to a couple of bad scenarios:

    1) the user thinks your page is broken, and either reports it
    to you (or your boss) or simply stops using it.

    2) the user is typing along, accidentally hits an invalid key,
    realizes it and hits the backspace. Since you already removed
    the invalid key, their backspace deletes the previous character,
    possibly without their noticing it.

    Besides these cases, you still aren't protecting yourself from
    invalid characters unless you validate the input on the server,
    too.

    Comment

    Working...