Skip to content

Instantly share code, notes, and snippets.

@shawnrgrimes
Created August 16, 2013 20:19
Show Gist options
  • Save shawnrgrimes/6253194 to your computer and use it in GitHub Desktop.
Save shawnrgrimes/6253194 to your computer and use it in GitHub Desktop.
Form inputs that remember default values. Example: http://jsfiddle.net/shawnrgrimes/rv8xY/
// Inputs that remember value
$(':text')
.each(function (currentIndex) {
$(this).data("originalValue", this.value);
})
.focus(function () {
$(this).removeClass("unfocused");
if ($(this).val() === $(this).data("originalValue")) {
$(this).val('');
}
})
.blur(function () {
if ($(this).val() === '') {
$(this).val($(this).data("originalValue"));
$(this).addClass("unfocused");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment