I want to be able to do something like
<input type="text" name="txtField" value="" title="input your text" />
<textarea name="areaField" title="input your long text"></textarea>
And the title will auto fade out and back in as the field value, unlike the “search” here in stackoverflow (right on the top, it only fade out).
I could come up with a javascript and use onblur and onfocus, but that would be troublesome and I hope unnecessary. Preferably, I’d set just a single function for every INPUT and TEXTAREA within any given file, so all I need to do is set up its title.
First question: what’s the name for this?
Main question: Anyone have a good solution? What about with no jquery? Maybe there’s a way to do it with CSS3 only, though I doubt it…
If you’re OK with it only working in newer browsers, you could use the
placeholderattribute on the text field, to supply a placeholder that will disappear when you focus and reappear when you blur. You can find some more info in Dive Into HTML5.If you want it to work in older browsers, you’ll probably have to implement the placeholder yourself, in JavaScript for instance. You can find all of your
inputandtextareaelements usingdocument.getElementsByTagNameand add theonfocusandonblurhandlers to each of those using DOM events.