Monday, December 19, 2011

Create Water Mark Text Box using JavaScript

we can create this using JavaScript code is given below:
----------------------------------------------------------------------------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
 
         <script language="javascript" type="text/javascript">
        function Focus(objname, waterMarkText) {
            obj = document.getElementById(objname);
          
                obj.value = "";
                if (obj.value == "Aditya" || obj.value == "" || obj.value == null) {
                    obj.style.color = "black";
             
            }
        }
        function Blur(objname, waterMarkText) {
            obj = document.getElementById(objname);
            if (obj.value == "") {
                obj.value = waterMarkText;
                                             
            }
                  if (obj.value == "Aditya" || obj.value == "" || obj.value == null) {
                obj.style.color = "gray";
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
      <table>
        <tr>
            <td>
                User Name
            </td>
            <td>
                <asp:TextBox ID="txtUserId" runat="server"
        onfocus="Focus(this.id,'Aditya')"
                    onblur="Blur(this.id,'Aditya')"
            Width="126px" style="background-color:pink" >Aditya</asp:TextBox>
            </td>
        </tr>
      </table>
    </form>
</body>
</html>
------------------------------------------------------------------------------------
try this

No comments:

Post a Comment