form submission

Feb 22, 2010 at 11:45 PM

 

I have updated the code to remove the hint when the form is submitted.


(function($) {
    jQuery.fn.inputHints = function() {
        // hides the input display text stored in the title on focus
        // and sets it on blur if the user hasn't changed it.

        // show the display text
        $(this).each(function(i) {

            var item = $(this);

            var title = item.attr('title');
            title = title + '  ';
            item.attr('title', title);

            addHint();

            // hook up the blur & focus
            item.parents('form').submit(removeHint);
            item.focus(removeHint);
            item.blur(addHint);

            function removeHint() {
                if (item.val() == title)
                    item.val('').removeClass("hint"); ;
            }

            function addHint() {
                if ($(this).val() == '')
                    item.val(title).addClass("hint"); ;
            }
        });
    };
})(jQuery);