Water Mark in textbox using java script asp.net c#


Source Code :-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="watermark.aspx.cs" Inherits="watermark" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Water Mark</title>

<script language="javascript" type="text/javascript">
    function WaterMark(txtName, event) {
        var defaultText = "Enter Username Here";
          if (txtName.value.length == 0 & event.type == "blur") {
            txtName.style.color = "Red";
            txtName.value = defaultText;
        }
       
        if (txtName.value == defaultText & event.type == "focus") {
            txtName.style.color = "Green";
            txtName.value = "";
        }
    }
</script>
    <style type="text/css">
        .style1 {
            font-size: large;
        }
    </style>
</head>
<body>
<form id="form1" runat="server">
<div>
    <strong><span class="style1">Name</span></strong>
<asp:TextBox ID="txtName" runat="server" Text="Please Enter Your Name" 
        onblur = "WaterMark(this, event);" onfocus = "WaterMark(this, event);"
        Width="186px" />
</div>
</form>
</body>
</html>




OUT-PUT:-

Water Mark in textbox using java script asp.net c# Water Mark in textbox using java script asp.net c# Reviewed by NEERAJ SRIVASTAVA on 11:01:00 PM Rating: 5

No comments:

Powered by Blogger.