Monday, 26 March 2012

Creating A WaterMark TextBox

Some times it requires a watermark  or a faded text to be placed in the text-box with default text on it.
We can design such using JQuery.you can use even a simple HTML controls to for this one. Here is the Code below:

·         
  WaterMark TextBox:
var swap = [];
              $(".waterMark").each(function (i) {

                swap[i] = $(this).val();

                $(this).focus(function () {
                    if ($(this).val() == swap[i])
                        $(this).val("").removeClass("waterMark");

                })
                .blur(function () {
if ($.trim($(this).val()) == "")
                        $(this).val(swap[i]).addClass("waterMark");
                })


            });
Mark Up:
<asp:textbox cssClass="waterMark" id="tbName" text="Your Name goes here..." runat="server"/>

Enjoy.........!

No comments:

Post a Comment