CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

WaterMark in ASP.Net TextBox using JavaScript
Submitted By Satheesh Babu B
On 4/7/2009 9:32:37 AM
Tags: CodeDigest,JavaScript  

WaterMark in ASP.Net TextBox using JavaScript

 

Watermark textbox are really useful to let the users to know the purpose of the textbox. Read my previous article - Creating Watermark TextBox in ASP.Net using JQuery to implement the feature using jQuery.

 

The following code snippet will help us doing this using JavaScript.

 

<head runat="server">

    <title></title>

    <script language="javascript">

        function DoWaterMarkOnFocus(txt, text) {

            if (txt.value == text) {

                txt.value = "";

            }

        }

        function DoWaterMarkOnBlur(txt, text) {

            if (txt.value == "") {

                txt.value = text;

            }

        }

    </script>

</head>

 

<body>

    <form id="form1" runat="server">

    <div>

    <asp:textbox ID="txtSearch" Text="Search..." onfocus="DoWaterMarkOnFocus(this,'Search...')" onblur="DoWaterMarkOnBlur(this,'Search...')"  runat="server"></asp:textbox>

 

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..