Hi nedash,
Refer the below sample code.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
window.onload = function SetColorOnPageLoad() {
var defalutNameText = "enter your name";
var defalutTellText = "enter your tell";
functionSetColor(document.getElementById("TextBox1"), defalutNameText);
functionSetColor(document.getElementById("TextBox2"), defalutTellText);
}
function functionSetColor(Textbox, WaterMark) {
if (Textbox.value.length > 0 && Textbox.value == WaterMark) {
Textbox.style.color = "#b1b1b1";
} else {
Textbox.style.color = "black";
}
}
function WaterMark(txt, evt, msg) {
if (txt.value.length == 0 && evt.type == "blur") {
txt.style.color = "#b1b1b1";
txt.value = msg;
}
if (txt.value == msg && evt.type == "focus") {
txt.style.color = "black";
txt.value = "";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input name="TextBox1" type="text" value="enter your name" id="Text1" class="txtSef"
onpaste="return false;" onblur="WaterMark(this, event,'enter your name');"
onfocus="WaterMark(this, event,'enter your name');" style="color: #B1B1B1;" />
<input name="TextBox2" type="text" value="enter your tell" id="Text2" class="txtSef"
onpaste="return false;" onblur="WaterMark(this, event,'enter your tell');"
onfocus="WaterMark(this, event,'enter your tell');" style="color: #B1B1B1;" />
<input type="button" name="btnText" value="Text" id="Submit1" />
</div>
</form>
</body>
</html>
Demo
Below is the ASP controls that you need to replace with the html controls.
<asp:TextBox ID="TextBox1" runat="server" CssClass="txtSef" Text="enter your name"
onpaste="return false;" ForeColor="#b1b1b1" onblur="WaterMark(this, event,'enter your name');"
onfocus="WaterMark(this, event,'enter your name');"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" CssClass="txtSef" Text="enter your tell"
onpaste="return false;" ForeColor="#b1b1b1" onblur="WaterMark(this, event,'enter your tell');"
onfocus="WaterMark(this, event,'enter your tell');"></asp:TextBox>
<asp:Button ID="btnText" Text="Text" runat="server" />