How to create JavaScrip watermark textbox ?

Ranjeet_8
Posted by Ranjeet_8 under JavaScript category on | Points: 40 | Views : 1123
JavaScript

<script language="javascript" type="text/javascript">
function WmarkFocus(txtName, WmarkStr) {
if (txtName.value == WmarkStr) txtName.value = '';
}
function WmarkBlur(txtName, WmarkStr) {
if (txtName.value == '') txtName.value = WmarkStr;
}
</script>

.ASPX Page

<asp:TextBox ID="txtWmark" runat="server" Width="200px" />

.CS Page

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string WmarkStr = "dotnetfunda search";
txtWmark.Text = WmarkStr;
txtWmark.Attributes.Add("onfocus", "WmarkFocus(this, '" +
WmarkStr + "');");
txtWmark.Attributes.Add("onblur", "WmarkBlur(this, '" +
WmarkStr + "');");
}
}

Comments or Responses

Login to post response