Cross-browser realtime restricted text in INPUT?

Discussion in 'Javascript' started by Rancid Buttchutney, Oct 29, 2006.

  1. 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.
     
    Rancid Buttchutney, Oct 29, 2006
    #1
    1. Advertising

  2. Rancid Buttchutney

    RobG Guest

    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
     
    RobG, Oct 30, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    4,741
    Ben Amada
    Jul 27, 2005
  2. Replies:
    0
    Views:
    354
  3. Jeff
    Replies:
    13
    Views:
    1,155
    vanilla
    Oct 6, 2007
  4. msdngroup
    Replies:
    5
    Views:
    721
    msgroup
    Jan 30, 2008
  5. johkar

    Access to input type - cross-browser

    johkar, Feb 8, 2005, in forum: Javascript
    Replies:
    1
    Views:
    80
    Fred Oz
    Feb 8, 2005
Loading...

Share This Page