I have a input box that i have some text in site
<input type="text" value="Enter Name"/>
Now i need to add that when the user starts typing in something (enters the first letter), my text will disappear and he will be able to enter the input he wants.
I tried doing:
$('#input').keypress(function () {
$(this).val("");
});
But then the user can only enter one letter cuz it keeps on deleting the text.
How can this be done?
Thanks
You can do this by using a placeholder
Demo:
http://jsfiddle.net/9VhYZ/
Some browser doesn’t yet support this, adding a fallback could also be a good idea to support it cross browser:
http://davidwalsh.name/html5-placeholder
UPDATE:
You can do what you ask for like this:
http://jsfiddle.net/9VhYZ/1/