471,316 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 software developers and data experts.

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
Jul 23 '05 #1
1 1355
Lee
JimO said:

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.


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.

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by lkrubner | last post: by
3 posts views Thread by Marcob | last post: by
1 post views Thread by =?Utf-8?B?Sm9obiBHcmF2ZXM=?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.