Link to home
Start Free TrialLog in
Avatar of vbnewbie01
vbnewbie01

asked on

clear textbox/fill textbox

hi there; using asp.net 2.0 (vb), i have the following textbox with default text displaying.

<asp:TextBox ID="txtTextbox" Text="Enter Name" onclick="txtTextbox.value ='';" AutoComplete="off" MaxLength="120" runat="server"></asp:TextBox>

when the user clicks inside the textbox, the default disappears.  what i would like to add is if the user clicks outside of the textbox without adding anything, the default text reappears.

suggestions?  thanks all.

                           
Avatar of Chandan_Gowda
Chandan_Gowda
Flag of United States of America image

This code will do it, in your Page_Load:

    TextBox1.Attributes.Add("onfocus", "if(this.value.toLowerCase() == 'your name') this.value = '';")
txtTextbox.Attributes.Add("onfocus", "if(this.value.toLowerCase() == 'enter name') this.value = '';")
ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vbnewbie01
vbnewbie01

ASKER

thanks, Chandan_Gowda.  right idea but not quite what i was looking for.  b0lsc0tt; exactly what i needed.  forgot about the onblur .... been awhile since i played with javascript (c:

thanks again, guys.
Your welcome!  I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol