I have an input field:
<input name="Name" value="Enter Your Name">
How would I get it to remove the pre-defined text (Enter Your Name) when the user clicks the box.
As far as I am aware Javascript is the best way to do this. If that wrong please inform me.
HTML5 Placeholder Attribute
You are likely wanting
placeholderfunctionality:Polyfill for Older Browsers
This will not work in some older browsers, but polyfills exist (some require jQuery, others don’t) to patch that functionality.
“Screw it, I’ll do it myself.”
If you wanted to roll your own solution, you could use the
onfocusandonblurevents of your element to determine what its value should be:Avoid Mixing HTML with JavaScript
You’ll find that most of us aren’t big fans of evaluating JavaScript from attributes like
onblurandonfocus. Instead, it’s more commonly encouraged to bind this logic up purely with JavaScript. Granted, it’s a bit more verbose, but it keeps a nice separation between your logic and your markup:Demo: http://jsbin.com/azehum/2/edit