PowerEdgeTech
asked on
How to clear pre-filled textBox on selection
I have a simple asp:textbox in a form on a webpage. I would like to prefill the box with the type of information expected (I.e. Name, Email, Phone, etc.) instead of having to label the box. I have the boxes pre-filled using Text="Name", but I would like to have the pre-filled content cleared when the user clicks in the box - or at least highlighted when clicked to be overwritten by the user's input.
Using focus seems to work on JavaScript INPUT field, but I can't get it to work the same way on asp:textbox. Is there an easy/good way to do this?
Be nice and keep it simple (if possible) ... I can follow most code, but I do consider myself a beginner :)
Thanks.
Using focus seems to work on JavaScript INPUT field, but I can't get it to work the same way on asp:textbox. Is there an easy/good way to do this?
Be nice and keep it simple (if possible) ... I can follow most code, but I do consider myself a beginner :)
Thanks.
What is a javascript input field and what makes an asp textbox not a normal input field when rendered?
Try this
emailaddress.Attributes.Ad d("onFocus ", "this.value=''"); <<<< not that the ='' are two single quotes
Try this
emailaddress.Attributes.Ad
Come on leakim, give someone else a chance to answer.
Anyway, my comment was codebehind
Anyway, my comment was codebehind
ASKER
I have been successful using onfocus on javascript input boxes, but I need this to work on an asp:textbox.
@mplungjan you right Boss ;-)) See you soon!
ASKER
For example, I can use JavaScript here to clear the contents:
<input id="fname" type="text" value="First Name" onFocus="this.value=''">
What I need is the same kind of functionality for the following VB.NET form:
<asp:TextBox id="Name" runat="server" Text="Name" />
I noticed that adding the onFocus="this.value=''" to it will actually clear it, I guess my question is ... Since this doesn't seem to be supported by the asp:textbox control, is it ok to do it this way? Is there a better way I "should" be doing this? Again ... beginner :)
<input id="fname" type="text" value="First Name" onFocus="this.value=''">
What I need is the same kind of functionality for the following VB.NET form:
<asp:TextBox id="Name" runat="server" Text="Name" />
I noticed that adding the onFocus="this.value=''" to it will actually clear it, I guess my question is ... Since this doesn't seem to be supported by the asp:textbox control, is it ok to do it this way? Is there a better way I "should" be doing this? Again ... beginner :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect!
If this works
TextBox1.Attributes["oncli ck"] = "clearTextBox(this.id)";
then this shoould work too
TextBox1.Attributes["oncli ck"] = "this.value=''";
no?
TextBox1.Attributes["oncli
then this shoould work too
TextBox1.Attributes["oncli
no?
ASKER
Yes, I can see now that it does, and perhaps I should have split some of the points to you, but Kris remembered that I am a beginner and spelled the solution out so it made sense to me. His answer "clicked", so I chose it.
Open in new window