Wednesday, 7 January 2015

Watermark in Textbox by javascript

 Watermark in Textbox by javascript:

Please write the script in aspx page:
 <script type="text/javascript">
        function WaterMarkFocus(txt, text) {
            if (txt.value == text) {
                txt.value = "";
                txt.style.color = "black";
            }
        }

        function WaterMarkBlur(txt, text) {
            if (txt.value == "") {
                txt.value = text;
                txt.style.color = "gray";
            }
        }
</script>

And write the code for Textbox:
<asp:TextBox ID="txtName" runat="server" Height="22px" Width="50px" Text="Name" onfocus="WaterMarkFocus(this,'Name')" onblur="WaterMarkBlur(this,'Name')"></asp:TextBox>


No comments:

Post a Comment