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:
This works in modern browsers. If you add modernizr.js to your page then it'll work in all browsers.
html
jQuery
demo
Make the input transparent and put the text behind it. Check the value onload, onblur to decide if the text should be visible or not. Make it invisible onfocus.
For example: http://dorward.me.uk/tmp/label-work/example.html (you just need to style the label and input with different foreground colours)
Look at this one: http://fuelyourcoding.com/scripts/infield/
placeholder code - name
name of the variable is,
DEMO LINK