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.
Enter the following inside the
tag, just add onFocus="value=''" so that your final code looks like this:
This makes use of the javascript onFocus() event holder.
we can do it without using js in the following way using the "placeholder" attribute of html5 ( the default text disappears when the user starts to type in ,but not on just clicking )
<input type="email" id="email" placeholder="xyz@abc.com">
see this: http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_input_placeholder
Here is a jQuery solution. I always let the default value reappear when a user clears the input field.
For future reference, I have to include the HTML5 way to do this.
If you have a HTML5 doctype and a HTML5-compliant browser, this will work. However, many browsers do not currently support this, so at least Internet Explorer users will not be able to see your placeholder. However, see http://www.kamikazemusic.com/quick-tips/jquery-html5-placeholder-fix/ (archive.org version) for a solution. Using that, you'll be very modern and standards-compliant, while also providing the functionality to most users.
Also, the provided link is a well-tested and well-developed solution, which should work out of the box.
Here is an easy way.
#animal
represents any buttons from the DOM.#animal-value
is the input id that being targeted.I didn't see any really simple answers like this one, so maybe it will help someone out.