What's the best way to have a text input field that displays instructions of what to enter in that field in gray. When you focus on that input field, the gray instruction text disappears and your input text appears black. If you erase your input text and focus away from that input, then the instruction gray text reappears.
I've tried implementing this with jQuery, but I get all kinds of weird issues with different browsers. Sometimes when you go back a screen, the instruction text becomes black and no longer disappears, issues like that.
Is there a standard javascript library for this? I can't find any!
Oh, and the instruction text can't be an image because it has to be available in different languages depending on the browser's language preference.
You don't need javascript for this.
HTML5:
<input type="text" id="email" name="email" placeholder="Enter your email address">
This works in modern browsers. If you add modernizr.js to your page then it'll work in all browsers.
You can use watermark plugin in jquery.use this link.
example
$(this).Watermark("your instructions");
<input type="text" id="user" class="textbox default" value="Enter login name">
<input type="password" id="pass" class="textbox">
$(function(){
$('.textbox').focus(function(){
if (this.value == this.defaultValue) {
this.value = '';
$(this).removeClass('default');
};
}).blur(function(){
if (this.value == '') {
this.value = this.defaultValue;
$(this).addClass('default');
};
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With