Question about <input type="text" name="firstname">, and auto-clearing contents

Discussion in 'Javascript' started by alxasa@gmail.com, Feb 1, 2007.

  1. Guest

    Hello, I am hoping someone can help me with this. I need a javascript
    function, which sits inside a <input type="text" name="firstname">
    line of code. Now, if someone starts typing fine, but when it goes 1
    character past 15 characters (15 characters only allowed), in this
    case I would like the contents of the input to be cleared out
    (automatically), and reset the input and its value back to nothing. a)
    Can this be done, and will someone please show me to do?? :) Thank
    you so much!! AngieX
    , Feb 1, 2007
    #1
    1. Advertising

  2. Lee Guest

    said:
    >
    >Hello, I am hoping someone can help me with this. I need a javascript
    >function, which sits inside a <input type="text" name="firstname">
    >line of code. Now, if someone starts typing fine, but when it goes 1
    >character past 15 characters (15 characters only allowed), in this
    >case I would like the contents of the input to be cleared out
    >(automatically), and reset the input and its value back to nothing. a)
    >Can this be done, and will someone please show me to do?? :) Thank
    >you so much!! AngieX


    Yes, it can be done, but it's a bad idea.

    If you had typed 15 characters, then accidentally hit another
    character instead of the TAB key, how would you feel if your
    input was deleted? I'd be unhappy. If I was about to buy
    something, I would find another vendor. If it was an internal
    application, I would complain to the appropriate management.

    Give them a chance to hit the backspace key to correct their
    mistake. If they actually leave the field after entering too
    many characters, alert them in some way and select the text they
    typed so that they can easily choose to either delete it all and
    start over or simply fix a typing mistake.


    --
    Lee, Feb 1, 2007
    #2
    1. Advertising

  3. Daz Guest

    On Feb 1, 6:53 pm, wrote:
    > Hello, I am hoping someone can help me with this. I need a javascript
    > function, which sits inside a <input type="text" name="firstname">
    > line of code. Now, if someone starts typing fine, but when it goes 1
    > character past 15 characters (15 characters only allowed), in this
    > case I would like the contents of the input to be cleared out
    > (automatically), and reset the input and its value back to nothing. a)
    > Can this be done, and will someone please show me to do?? :) Thank
    > you so much!! AngieX



    It would probably be wiser to just use the MAXLENGTH attribute for the
    text input field. If you limit this to 15, and make it long enough to
    fit only fifteen characters into, the user should soon notice they
    can't fit more characters into it. Even better still would be to tell
    the user that they shouldn't enter more than 15 characters. That way,
    there can be no mistaking.

    You will also need to take into account what would happen if the user
    doesn't have JavaScript enabled, or if their browser doesn't support
    it. All data should be validated on the server side, too. You should
    not be relying on client side validation, as there is so much that can
    go wrong, either with the browser, or due to the user changing the
    source at their end. In general, JavaScript should only be used to
    validate a user's input in such a way that it's not relied upon by the
    code on your server. I often find it best to created my page, and
    imagine that JavaScript does not exist. Once done, then I add the
    JavaScript, so it will work with or without almost flawlessly.

    Hope this helps.

    Daz.
    Daz, Feb 1, 2007
    #3
    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. =?Utf-8?B?S2VuIEFkZW5pamk=?=

    Must declare the scalar variable '@FirstName'

    =?Utf-8?B?S2VuIEFkZW5pamk=?=, Apr 26, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    80,069
    leojose
    Aug 17, 2007
  2. Nico Grubert
    Replies:
    0
    Views:
    246
    Nico Grubert
    Jan 10, 2006
  3. abargaddon
    Replies:
    2
    Views:
    22,979
    abargaddon
    Feb 2, 2008
  4. linkswanted
    Replies:
    1
    Views:
    896
  5. Mark 123
    Replies:
    5
    Views:
    123
    Christopher J. Hahn
    Jul 4, 2005
Loading...

Share This Page