CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Creating Watermark TextBox in ASP.Net using JQuery
Submitted By Satheesh Babu B
On 2/6/2009 8:56:14 AM
Tags: ASP.Net,CodeDigest,JQuery  

Creating Watermark TextBox in ASP.Net using JQuery

We can use watermark textbox to let the users know about the purpose of the textbox i.e. it serves as help text to the users on what to type in. In internet, most of the websites will have search textbox as watermark textbox.

 

The following code snippet will help us to implement similar watermark textbox with asp.net textbox control and JQuery library.

 

Read my article Using JQuery in ASP.Net AJAX Applications - Part 1 to know more about JQuery and integrating it to ASP.Net AJAX application.

 

<head>
<script src="_scripts/jquery-1[1].2.6.js" type="text/javascript"></script>

<script language="javascript">
$(document).ready(function() {
var watermark = "Type your query..";
if ($("#txtSearch").val() == "") {
$("#txtSearch").val(watermark);
}

$("#txtSearch").focus(function() {
if (this.value == watermark) {
this.value = "";
}
}).blur(function() {
if (this.value == "") {
this.value = watermark;
}
});
});
</script>

</head>

<asp:TextBox ID="txtSearch" runat="server" ></asp:TextBox>

 

Read the other JQuery snippets here.

 

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..