Clearing a field's default text
Last modified: February 1, 2009 - 12:04
It's often useful to have default text in a field. For example search boxes that say "Enter some search terms", or example text. But selecting this text to overwrite it is a pain for the user.
Here is a snippet of jquery to blank a field on first click (and then not blank it any more, obviously).
/**
* Clears field texts on click.
*/
$(document).ready(function() {
$('YOUR SELECTOR HERE').click(function () {
$(this).attr('value', '');
$(this).unbind('click');
});
});
