vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Sunday, January 1, 2012

Apply watermark text in textbox using javascript in asp.net


Hi..
Introductoin:

Here I have share the ideas to show water mark text n texbox.i hope many of them looking for watermark text.
Description:

I achieve the watermark text using JavaScript..By using script we can write the code in many ways..Here one of the easiest way to write using javascript.
In textbox we use two events onfocus() and onblur()

Onfocus-this event call when we click on the textbox

Onblur-This event call, when we leave mouse from the textbox.

Code:
    <script type="text/javascript">

        function rem(id) {
            var txt = id.value;
            if (txt == "Name") {
                id.value = "";
            }
            if (txt == "Address") {
                id.value = "";

            }
            if (txt == "Dob") {

                id.value = "";
            }
        }
        function add(id, id1) {

            var txt = id.value;
            if (id1 == "Name") {
                if (txt == "") {
                    id.value = "Name";

                }
            }
            if (id1 == "Address") {
                if (txt == "") {
                    id.value = "Address";

                }
            }
            if (id1 == "Dob") {
                if (txt == "") {
                    id.value = "Dob";

                }
            }

        }
    </script>

   <div>
        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox1" runat="server" onfocus="rem(this);" onblur="add(this,'Name');" Text="Name"></asp:TextBox>&nbsp;&nbsp;
        <asp:TextBox ID="TextBox2" runat="server" onfocus="rem(this);" onblur="add(this,'Address');" Text="Address"></asp:TextBox>&nbsp;&nbsp;
        <asp:TextBox ID="TextBox3" runat="server" onfocus="rem(this);" onblur="add(this,'Dob');" Text ="Dob"></asp:TextBox>&nbsp;&nbsp;
    </div>



I hope you’re learned something useful…………
Plz post your comments.

0 comments:

Post a Comment