I have an input text :
<input name="Email" type="text" id="Email" value="email@abc.com" />
I want to put a default value like "What's your programming question ? be specific." in StackOverFlow, and when the user click on it the default value disapear.
<input name="Email" type="text" id="Email" placeholder="enter your question" />
The placeholder attribute specifies a short hint that describes the expected value of an input field (e.g. a sample value or a short description of the expected format).
The short hint is displayed in the input field before the user enters a value.
Note: The placeholder attribute works with the following input types: text, search, url, tel, email, and password.
I think this will help.
This is somewhat cleaner, i think. Note the usage of the "defaultValue" property of the input:
Just use a
placeholder
tag in your input instead ofvalue
Here is very simple javascript. It works fine for me :
Using jQuery, you can do:
And you could stuff all this into a custom plug-in, like so:
Here's how you would use the plug-in:
Advantages to using this code is:
Non-jQuery approach:
EDIT: Although, this solution works, I would recommend you try MvanGeest's solution below which uses the
placeholder
-attribute and a javascript fallback for browsers which don't support it yet.If you are looking for a Mootools equivalent to the JQuery fallback in MvanGeest's reply, here is one.
--
You should probably use
onfocus
andonblur
events in order to support keyboard users who tab through forms.Here's an example: