Fields that remember value.

by Shawn Grimes

HTML

<input type="text" value="hello!">
<input type="text" value="hello again!">
<input type="text" value="hello good sir!">

JavaScript

// 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");
    }
});