TNK
TNK

Reputation: 4323

modifying jquery function to match textarea

I use this jquery function to show a hint in form's inputs. Now I need to modify this function to display a hint in textarea too. can anybody help me to do this.?

function textboxHint(id, options) {
    var o = { selector: 'input:text[title]', blurClass:'blur' };
    $e = $('#'+id);
    $.extend(true, o, options || {});

    if ($e.is(':text')) {
      if (!$e.attr('title')) $e = null;
    } else {
      $e = $e.find(o.selector);
    }
    if ($e) {
      $e.each(function() {
      var $t = $(this);
      if ($.trim($t.val()).length == 0) { $t.val($t.attr('title')); }
      if ($t.val() == $t.attr('title')) {
    $t.addClass(o.blurClass);
      } else {
        $t.removeClass(o.blurClass);
      }

     $t.focus(function() {
    if ($.trim($t.val()) == $t.attr('title')) {
      $t.val('');
      $t.removeClass(o.blurClass);
    }
    }).blur(function() {
      var val = $.trim($t.val());
      if (val.length == 0 || val == $t.attr('title')) {
        $t.val($t.attr('title'));
        $t.addClass(o.blurClass);
      }
    });

         // empty the text box on form submit               
    $(this.form).submit(function(){
      if ($.trim($t.val()) == $t.attr('title')) $t.val('');
    });
   });
 }
}   

I simple use this in my script like this..

textboxHint("block1");

NOTE: I use TITLE attribute to add the hint..

Upvotes: 0

Views: 46

Answers (1)

3dgoo
3dgoo

Reputation: 15794

I would think you just need to add textarea to your select like this:

var o = { selector: 'input:text[title], textarea[title]', blurClass:'blur' };

Upvotes: 1

Related Questions