469,599 Members | 2,775 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,599 developers. It's quick & easy.

Cross-browser realtime restricted text in INPUT?

I've tried searching the web but I've had little success finding a
cross-browser(IE, Firefox and Opera anyway) implementation of a
restricted text INPUT that works in realtime before a character is even
displayed in the field. Is there a working implementation anywhere?

And how about denial of cross-browser pasting? On Windows a popup menu
appears with the clipboard pasting options and I'd like to disable that
and CTRL-V in an INPUT too.

Oct 29 '06 #1
1 1850
Rancid Buttchutney wrote:
I've tried searching the web but I've had little success finding a
cross-browser(IE, Firefox and Opera anyway) implementation of a
restricted text INPUT that works in realtime before a character is even
displayed in the field. Is there a working implementation anywhere?
The HTML maxlength attribute is pretty robust. There are many scripts
availble, search the archives of this news group. They are of limited
use as they only work if scripting is enabled - which probably creates
more issues than cross-browser compatability.

If you want to stop something from being displayed, you have to use the
keydown event to see which key(s) have been pressed and work out
whether to cancel the event or allow it to proceed. That logic can
become extensive, as once you have reached your maximum number of
characters you still want to allow key strokes like delete, backspace,
cursor keys, etc.

Users can also select multiple characters and enter a single character
to replace them, hence the use of keyup or keypress events to see what
the user actually did before trying to modify their behaviour.
Therefore most scripts wait until the user has finished entering text
before trying to validate it.

A good solution is to use an on-screen message based on keypress to
advise of invalid input rather than trying to modify the input's value.
The message appears when invalid input is detected, then disappears
when it is fixed. It keeps the user in control and doesn't try to
force them into any particular behaviour - how they achieve valid input
is totally up to them. The value of an input only has to be valid
*when the form is submitted*, not at some random point in time before
then.

And how about denial of cross-browser pasting? On Windows a popup menu
appears with the clipboard pasting options and I'd like to disable that
and CTRL-V in an INPUT too.
Impossible to do reliably in even a few browsers, much less all.
--
Rob

Oct 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Scott M. | last post: by
3 posts views Thread by jlamanna | last post: by
1 post views Thread by Rob Woodworth | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.