0

I wanna have a the text "Username" in the username-Textbox in gray until the user clicks it. When he enters something the box should be empty auhtomaticly and black color again.

How to do that?

PassionateDeveloper
  • 14,558
  • 34
  • 107
  • 176
  • possible duplicate of [Input placeholders for Internet Explorer](http://stackoverflow.com/questions/5522164/input-placeholders-for-internet-explorer) – CodeCaster Sep 29 '13 at 11:27

3 Answers3

1

You should check asp.net ajax watermark extender for cross browser compatibility:

Link

First you need to include ajaxToolkit, then you can use it like this:

<ajaxToolkit:TextBoxWatermarkExtender ID="TBWE2" runat="server"
    TargetControlID="**YouTextBoxID**"
    WatermarkText="Type First Name Here"
    WatermarkCssClass="watermarked" />
Tomzan
  • 2,808
  • 14
  • 25
1

modern browsers which support css3 like chrome allows a placeholder attribute to the input elements. Example:

<input name="username" placeholder="User name" />

Reference: http://www.w3schools.com/tags/att_input_placeholder.asp

Alternative is to use javascript onfocus/onblur to show/delete the placeholder text inside textbox

Rajesh
  • 3,743
  • 1
  • 24
  • 31
1

As @rajesh mentioned, you can use placeholder attribute in modern browsers.

For older browsers, search for "html textbox watermark". Here's some good javascript solutions,

Community
  • 1
  • 1
Kamyar
  • 18,639
  • 9
  • 97
  • 171