We have a survey where certain pages have a single textarea question. Since it’s the only input, we want to have it focus on that box onload. But we also want to have a placeholder-style text in that same textarea.
There are quite a few solutions to making both functions work on all browsers such as this one by Ajaxblender. But I want the hint to remain after focus, then disappear when text is entered. Any ideas?
Note – I realize the HTML specs state that the placeholder element should going away on focus. So maybe I should say that I want a “watermark”. This UI is for older men with low computer literacy – they need any assistance we can provide them.
Must work with IE8 🙁
If I understand the question, you could try something like
HTML
jQuery
Example: http://jsfiddle.net/jasongennaro/AYRyH/
Explanation
.focus()puts the focus on the field at onload..one()fires an event once for the elementkeydownwe remove the current value, which are the instructions we added at the beginning.EDIT
Given your comment
You could do this… capture the
valueand then place it back in thetextareaonblurif there is nothing there.Example 2: http://jsfiddle.net/jasongennaro/AYRyH/1/