473,651 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2254
Lee
al****@gmail.co m 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.co m 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
1667
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
5629
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 that array back into another file. I've tried, but i can only read the data and place it on the screen, i cant get it into an array. Any help would be helpful.
2
1433
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" width="800">' print '<tr><td colspan="2"><h2>' print 'Differences %s: %s' % (htypestr, lbl1) if html:
6
396
by: Du Dang | last post by:
Text: ===================== <script1> ***stuff A </script1> ***more stuff <script2> ***stuff B
4
1042
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 an XML file.
8
3656
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 and save it to a file. This step is not to hard however the contents of the textarea is mostly latex source so it contains just about every special character you can imagine. My question is this, how do I save an exact copy of the textarea...
9
10558
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
2764
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'; >> array_it.js set /a items=items+1 ) else (
1
2314
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 another command button the purpose of which is to permit one to set a breakpoint in the code behind the button
2
1822
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 ReadHtmlPage(string url) { WebResponse objResponse; WebRequest objRequest = System.Net.HttpWebRequest.Create(url); objResponse = objRequest.GetResponse();
0
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8697
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8579
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7297
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.