bismay4u
2/17/2012 - 10:19 AM

[GhostText] JQuery Plugin For Displaying Watermark Text On HTML Input-type=text Fields

[GhostText] JQuery Plugin For Displaying Watermark Text On HTML Input-type=text Fields

if(jQuery) (function($){
	$.extend($.fn, {
		ghosttext : function(shadowColor,ttlAttr) {
			if(shadowColor==null) shadowColor="#ccc";
			if(ttlAttr==null) ttlAttr="title";
			
			var txt=$(this).attr(ttlAttr);
			var clr=$(this).css("color");
			
			
			if(txt==null) return;
			
			$(this).val(txt);
			$(this).css("color",shadowColor);
			
			$(this).focus(function() {
				if($(this).val()==txt) {
					$(this).val("");
				}
				$(this).css("color",clr);
			});
			$(this).blur(function() {
				if($(this).val().length<=0) {
					$(this).val(txt);
					$(this).css("color",shadowColor);
				} else {
					$(this).css("color",clr);
				}
			});
		}
	});
})(jQuery);