Mojtaba
Mojtaba

Reputation: 51

TextBox with Default value

I want to use a textbox that shows a text.

For example : [email protected]. When the user clicks on it, the textbox is cleared and ready for the user to type.

sample textbox

Upvotes: 4

Views: 21084

Answers (6)

huddds
huddds

Reputation: 1045

You can use this ajax if you want a cross browser compatible version.

<ajaxToolkit:TextBoxWatermarkExtender ID="EmailClear" runat="server" TargetControlID="EmailAddress" WatermarkText="[email protected]" />

You just have to add this under each field.

Upvotes: 0

Alsan
Alsan

Reputation: 325

you can use this, is so easy

 <input class="status" type="text" size="5" placeholder="started"  />

placeholder show you the text you want

hope it helps you!

Upvotes: 2

Sagar Hirapara
Sagar Hirapara

Reputation: 1697

Try this for a server control:

<asp:TextBox ID="textBox1" runat="server" placeholder="[email protected]"></asp:TextBox>

For an HTML control:

<input Type="Text" ID="textBox1"  placeholder="[email protected]" />

Upvotes: 0

शेखर
शेखर

Reputation: 17614

You can use like this

<TextBox ID="txtone" runat="server" tooltip="Enter comments"
onblur="if(this.value=='') this.value='[email protected]';"
onfocus="if(this.value == '[email protected]') this.value='';"
Text="[email protected]"></TextBox>

Upvotes: 0

Imad Abu Hayyah
Imad Abu Hayyah

Reputation: 43

You can do the following:

  1. Add textbox to your webpage.
  2. Set the default text in the obj.Text property.
  3. Add properties ( focus & blur events).
  4. On focus event, check if the value = [email protected] , then empty the text box.
  5. On blur, check if the textbox is empty, then set the text : [email protected]

Hope that helps

Upvotes: 0

Sachin
Sachin

Reputation: 40970

If you are working on newer browsers then you can use placeholder property which is new in HTML 5

<asp:TextBox ID="textBox1" runat="server" placeholder="[email protected]"></asp:TextBox>

otherwise you can also use onfocus and onblur event to do this as described here

Upvotes: 6

Related Questions