About Me

My photo
a Dynamic and Energetic guy.....

Monday, December 6, 2010

Create a textbox watermark using JQuery




color: lightgrey;

font-style: italic;



<!--Add JQuery library reference-->



     $(document).ready(function () {

     var val = "User Name";

     //assign some watermark value into variable

     if ($("#HeadLoginView_LoginUser_UserName").val() == "") {



     //Check if user and enter into the textbox and remove the class we have assigned on focus event of the text Box

     $("#HeadLoginView_LoginUser_UserName").focus(function () {

     if (this.value == val) {

     this.value = "";

     $("#HeadLoginView_LoginUser_UserName").removeClass("watermark"); //remove class when user focus on the textbox



     // If user did not enter any value in the text box then assign back the watermark value and assign the class

     $("#HeadLoginView_LoginUser_UserName").blur(function () {

     if (this.value == "") {

     this.value = val;

     $("#HeadLoginView_LoginUser_UserName").addClass("watermark"); // Add class to the textbox





No comments:

My Masters