Introduction
When you click the textbox the text inside the textbox disappear and when the focus leave from the text box the text will appear.For this i gave one example code below
|
Preview
When you click the text box user name will disapear,when focus leave that will appear.
|
<script type="text/javascript" >
function do_highlight(ele) {
document.getElementById(ele.id).style.color = "black";
if (ele.id.indexOf("UserName") != -1 && document.getElementById(ele.id).value == "Username") {
document.getElementById(ele.id).value = "";
}
if (ele.id.indexOf("PassLog") != -1 && document.getElementById(ele.id).value == "Password") {
document.getElementById(ele.id).value = "";
}
}
function do_unfocus(ele) {
if (ele.id.indexOf("UserName") != -1 && document.getElementById(ele.id).value == "") {
document.getElementById(ele.id).value = "Username";
}
if (ele.id.indexOf("PassLog") != -1 && document.getElementById(ele.id).value == "") {
document.getElementById(ele.id).value = "Password";
}
if (ele.id.indexOf("UserName") != -1 && document.getElementById(ele.id).value == "Username")
document.getElementById(ele.id).style.color = "rgb(70,70,70)";
if (ele.id.indexOf("PassLog") != -1 && document.getElementById(ele.id).value == "Password")
document.getElementById(ele.id).style.color = "rgb(70,70,70)";
}
</script>
|
Calling the function to asp button
<asp:TextBox ID="UserName" runat="server" onfocus="do_highlight(this);" onblur="do_unfocus(this);" value="Username"
MaxLength="20" ForeColor="#707070"></asp:TextBox>
<asp:TextBox ID="PassLog" runat="server" onfocus="do_highlight(this);"onblur="do_unfocus(this);"value="Password"
ForeColor="#707070" MaxLength="10" TextMode="Password"></asp:TextBox>
|