Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Question about <input type="text" name="firstname">, and auto-clearing contents

Reply
Thread Tools

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

 
 
alxasa@gmail.com
Guest
Posts: n/a
 
      02-01-2007
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

 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      02-01-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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.


--

 
Reply With Quote
 
 
 
 
Daz
Guest
Posts: n/a
 
      02-01-2007
On Feb 1, 6:53 pm, (E-Mail Removed) 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding contents on yaml file without overwriting actual contents Kamarulnizam Rahim Ruby 4 01-28-2011 09:10 AM
possible viewport question, need to control what portion of div contents appear when overflow:auto and too much content in div Jake Barnes Javascript 1 09-05-2007 11:00 PM
<div question, getting fixed size of contents, not just character count lhjayunaz@gmail.com HTML 3 08-26-2007 09:58 PM
if innerHTML used twice then it replaces the contents i want it to display all the contents virendra.amritkar@gmail.com Javascript 0 06-29-2007 08:13 AM
Can I restrict both attribute contents and element contents in schema Don Adams XML 1 03-05-2004 12:48 PM



Advertisments