473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

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 '07 #1
2 2233
Lee
al****@gmail.com 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.
--

Feb 1 '07 #2
Daz
On Feb 1, 6:53 pm, alx...@gmail.com 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.

Feb 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Pekka Niiranen | last post by:
Hi, I have Perl code looping thru lines in the file: line: while (<INFILE>) { ... $_ = do something ... if (/#START/) { # Start inner loop
6
by: Foxy Kav | last post by:
Hi, another question from me again, i was just wondering if anyone could give me a quick example of reading data from a file then placing the data into an array for some manipulation then reading...
2
by: Dr. Who | last post by:
I have a tool that outputs data in either html or text output. Currently I'm writing chucnks like: if html: print '<html><body bgcolor="FFFFCC">' print '<table border="1" bgcolor="CCCCFF"...
6
by: Du Dang | last post by:
Text: ===================== <script1> ***stuff A </script1> ***more stuff <script2> ***stuff B
4
by: Earl | last post by:
Is it poor practice to have one custom library depend on another custom library? For example, my data manipulation library depends on my replication library, which in turn pulls serial data out of...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
9
by: cheng | last post by:
I was trying to figure out how & work, so I wrote the following code #include <iostream> using namespace std; void print(int &); int main() { int i = 10;
3
by: 95redtegls | last post by:
Ok here is my question Can javascript read the contents of a folder and list its path name in a array Here is what i have so far @echo off if '%1'=='w' ( echo Scenary='images/Scenary/%2';...
1
by: mirandacascade | last post by:
1) Module1 has the following delcaration: Public g_frmZZZ as Form Public g_txtForm2 as Variant 2) app has two forms: form1 and form2 3) a command button on form1 opens form2; it also has...
2
by: Ken Fine | last post by:
I have a question about ASP.NET output caching. I want to use screen scraping as a temporary hack to pull in some complex Classic ASP-rendered content into some ASP.NET pages: protected String...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.