473,804 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to clear a textbox on GotFocus in a web-page ?

Hi.

I have... well.... not very many computer-literate users to my web-
site.

For the textbox which expects an email address, for instance, I had to
enter a default text like
"Email..." because if not, they phoned me asking questions like "What
does the message 'Your email address is required' ?" :-)))

Now the problem is that many users don't erase this default text, and
enter their email address AFTER the default text, so that the contents
of the textbox is now
"Email...my**** @myISP.com"

On this textbox,I have, of course, a RequiredFieldVa lidator, another
RequiredFieldVa lidator (with InitialValue="E mail...") and a
RegularExpressi onValidator (with the regex
ValidationExpre ssion="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-
\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"

But this does not filter out the "Email... " text.

I *could* alter the ValidationExpre ssion, of course, but I would want
a more elegant solution, one which would clear the default text out on
a textbox on GOTFOCUS, and conversely, put the default text back on
LOSTFOCUS, if, of course, the text in that text-box has not been
changed from the default - if the text HAS been changed, then,
obviously, it has to be left there.

So, for example, say that txtEmail has the default contents
"Email...". You click in it, the text disappears. You click away, it
becomes "Email..." again. You click in it again, it becomes null
again. You type "mm*@mmm.co m" and you click away, the text stays
"mm*@mmm.co m".

I'm sure that this requires some JavaScript, but.... I don't know
enough JavaScript for this, unfortunately. Could you please direct me
to such a piece of code ?

Thank you very much.
Alex.

Jul 17 '07 #1
1 7209
Hi!

Well, I just have my social minutes :-)

<input type="text" name="useremail " value="Email... " size="20"
onfocus="if ( this.value == this.defaultVal ue ) this.value = ''"
onblur="if ( this.value == '' ) this.value = this.defaultVal ue" />

I assume you are using xhtml in that example. If you use html
instead then you should drop the / at the end. If you plan to
change the value which is written in the field by default you just
need to change the "value" attribute; the javascript will adapt
automatically.

Also, feel free to modify the size of the textbox by adjusting the
"size" attribute (which holds the number of visible characters in
the field)

This example does not filter its input in any way, so you need to
make that sure. But your regexp will do that :-)

bye
Alex <cu************ *@yahoo.comwrot e:
Hi.

I have... well.... not very many computer-literate users to my
web- site.

For the textbox which expects an email address, for instance, I
had to enter a default text like
"Email..." because if not, they phoned me asking questions like
"What does the message 'Your email address is required' ?" :-)))

Now the problem is that many users don't erase this default
text, and enter their email address AFTER the default text, so
that the contents of the textbox is now
"Email...my**** @myISP.com"

On this textbox,I have, of course, a RequiredFieldVa lidator,
another RequiredFieldVa lidator (with InitialValue="E mail...")
and a RegularExpressi onValidator (with the regex
ValidationExpre ssion="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-z
A-Z][- \w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"

But this does not filter out the "Email... " text.

I *could* alter the ValidationExpre ssion, of course, but I would
want a more elegant solution, one which would clear the default
text out on a textbox on GOTFOCUS, and conversely, put the
default text back on LOSTFOCUS, if, of course, the text in that
text-box has not been changed from the default - if the text HAS
been changed, then, obviously, it has to be left there.

So, for example, say that txtEmail has the default contents
"Email...". You click in it, the text disappears. You click
away, it becomes "Email..." again. You click in it again, it
becomes null again. You type "mm*@mmm.co m" and you click away,
the text stays "mm*@mmm.co m".

I'm sure that this requires some JavaScript, but.... I don't
know enough JavaScript for this, unfortunately. Could you please
direct me to such a piece of code ?

Thank you very much.
Alex.

Jul 17 '07 #2

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

Similar topics

4
4578
by: fmarchioni | last post by:
Hi all, I need to highlight textbox in a Form when they are selected. In order to do it I have added for each one a .GotFocus and .LostFocus Event Handler.... textRS.GotFocus += new EventHandler(gotFocus_Event); textName.GotFocus += new EventHandler(gotFocus_Event); textSurname.GotFocus += new EventHandler(gotFocus_Event); textAddress.GotFocus += new EventHandler(gotFocus_Event);
2
4462
by: Gopal Krishna Tengli | last post by:
Hi, I want to impliment the textbox's gotfocus event. Its not a intrincic event. So not listed in the editor. Waiting for an innovative reply... Gopal Krishna
10
9053
by: Jane Sharpe | last post by:
Hi, I have a textbox with the words "Enter your name here" inserted as default text - At the moment, to remove this the user must highlight all the text and delete before they type in their name - I've seen sites where all this text dissapears as soon as the user clicks on it - how do I do that ? Thanks Jane
12
1726
by: Gene Hubert | last post by:
How do I make a TextBox behave like the address bar in IE? That is... If focus is not on the tb, select all text if clicking on the tb or tabbing into the tb. Clicking again deselects the text and sets the insertion point to where clicked. I've tried several options inheriting from TextBox but none work quite right. Thanks Much,
10
3133
by: Dennis | last post by:
I have a simple form with one button and one text box. In the Form, I create an array list to track the events by adding a descriptive string item to the arraylist in each event. I first Click on the Button then Click on the TextBox and enter an "a" then click on the Button again. The following is what I get for the event tracking Arraylist: but - GotFocus but - Clicked but - LostFocus txt - Changed
2
8045
by: Jonathan Allen | last post by:
In dialog boxes in Windows, the text in TextBox is automatically selected if you tab into the TextBox , but not when you select the TextBox using the mouse. What is the preferred way to support this in VB/C# 2005? -- Jonathan Allen
8
21904
by: cj | last post by:
I asked this question a couple of days ago but am just now looking at it again. I used to use the textbox gotfoucs event to have all the text in the textbox selected when it gotfocus. That doesn't seem to work in .net when the textbox receives focus via a mouse click. Jeffrey and Shane both advised how to get a mouse click to select all the text (thank you both) but using the mousedown or mouseup events doesn't work the way I want it...
5
7460
by: =?Utf-8?B?QmVuIFIu?= | last post by:
Hi, In a .NET 2.0 winforms application, I've got a textbox that, when updated, uses the validated event to cascade the change to another textbox (along with another value). This works well if the user does indeed move the cursor to another textbox, but if the user clicks my "done" toolstripbutton after making a change in the textbox but without moving the cursor out, the validated event never fires. I have a pretty bad workaround where...
7
1617
by: Localbar | last post by:
Hi all, In my form have more then 10 textbox. I would like to make all textbox when lostfocus backcolor is white, when gotfocus backcolor is yellow. But I don't want to write same code in the form. How to solve this problem. Is it can make a textbox class to control or some other method? Thanks
10
18052
by: engteng | last post by:
When textbox properties enable = False the font in the textbox become gray color. How do I change the gray color to black color ? Regards, Tee
0
10337
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
10082
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...
1
7622
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
6854
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5525
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
5654
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
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
2
3822
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.