jQuery Meetups

jQuery Meetups

Easy Custom Watermark Textbox using JQuery

In recently i have checked one JQuery plugin for textbox watermark. This is working quite fine but this could be implemented easier than that plugin approach. 
1) Take a text box on aspx page.
  1. <asp:TextBox ID="txtValue" runat="server" Columns="25" MaxLength="70" Text="Type here to search" ></asp:TextBox>
2) then, place this code either in hearder tag or in separate JQuery File.
  1. $(document).ready(function () {
  2. $("#txtValue").css("background-color", "#EDEDED"); //You can use some more styling.
  3. $("#txtValue").bind("focusin", function () {
  4. $("#txtValue").val("");
  5. });
  6. $("#txtValue").bind("focusout", function () {
  7. $("#txtValue").val("Type here to search");
  8. });
  9. });

In this approach, i am using Textbox's text property. It is working fine in my case but might not appropriate in your case. So we can tweak it quite easily. In the below written code i'll use title/tooltip property instead on Text.
1) Take a text box on aspx page. Do not forgot to mention its Tooltip/title property.
  1. <asp:TextBox ID="txtValue" runat="server" Columns="25" MaxLength="70" ToolTip="Type here to search" ></asp:TextBox>
    1. $(document).ready(function () {
    2. $("#txtValue").css("background-color", "#EDEDED"); //You can use some more styling.
    3. $("#txtValue").bind("focusin", function () {
    4. $("#txtValue").val("");
    5. });
    6. $("#txtValue").bind("focusout", function () {
    7. $("#txtValue").val($("#txtValue").attr("title"));
    8. });
    9. });
    2) then, place this code either in hearder tag or in separate JQuery File.

Views: 2175

Tags: Watermark, textbox

Comment

You need to be a member of jQuery Meetups to add comments!

Join jQuery Meetups

Badge

Loading…

© 2013   Created by jqueryadmin.

Badges  |  Report an Issue  |  Terms of Service