Skip to content

Instantly share code, notes, and snippets.

@rmanalan rmanalan/gist:46340
Created Jan 13, 2009

Embed
What would you like to do?
jQuery plugin for the "input prompt" pattern
// Extracted from http://github.com/madrobby/prototype_helpers/tree/master/defaultValueActsAsHint
// Accepts JQuery elem as input for hiding/unhiding related elements.
$.fn.defaultValueActsAsHint = function(elems){
this.get(0)._default = this.attr('title');
return $(this).focus(function(){
if(this._default != this.value) return;
this.value = '';
$(this).removeClass('quiet');
elems.each(function(){$(this).show()});
}).blur(function(){
if(this.value.trim() != '') return;
this.value = this._default;
$(this).addClass('quiet');
elems.each(function(){$(this).hide()});
}).addClass('quiet').val(this.attr('title'));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.