My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Instructions  
I will teach you how to use the jQuery Watermark plugin.
Featured
Updated Mar 15, 2011 by mario.es...@gmail.com

Requirements

  1. Import jQuery from google or your local copy (Using google's copy):
  2. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  3. Below the previous code import the jQuery Watermark plugin from your local copy:
  4. <script type="text/javascript" src="../js/jquery.watermark.js"></script>
  5. Both lines could either be before the </body> closing tag or inside the <head> tag, it is recommended to import all javascript just after the closing <body> tag, because script downloads might delay the page display.

Instructions

Fast

  1. Add the 'jq_watermark' class to the input elements (works on text inputs and textareas).
  2. Add a title attribute to the elements, the content of the title attribute will be shown as the watermark text.
  3. Done :)

Options (Advanced)

  • Start the watermark plugin by using the '.watermark()' command on an input field. Eg.:
  • $('input#email').watermark();
  • The plugin accepts 2 arguments: 'text' & 'css_options'.
    • 'text' can define the text to be displayed, if no text is defined it will default to the 'title' attribute or the 'placeholder' attribute (HTML5) of the input element.
    • 'options' accepts the following options: 'color', 'top', 'left' & 'fallback*'.
      • 'color' specifies the color to use for the watermark label (defaults: '#999').
      • 'top' is a vertical offset which you can manipulate, as is 'left' for horizontal offset. The offsets can be negative.
      • 'fallback' option (defaults: false) detects if native HTML5 placeholder support is present and if it is the plugin won't load and will let the browser handle it.
      • $('input#email').watermark('Email', {color: '#333', left: -2, top: 10, fallback: true});

* New in 1.1.1

  • You can also define defaults to be used on all watermarked elements by using the 'setDefaults' function. Eg:
  • $.watermarker.setDefaults({ color: '#f00', left: 8 });
    $('input[type=text]').watermark();

Known Issues

  • Chrome (and other browsers) autofill may not trigger the change event on autofilled fields making the watermark labels appear on top of the text. You can use this as a fix, but it is not a very good one:
  • $('form input').change(function(e, was_triggered)
    {
      var form = $(this).closest('form');
      
      if(!was_triggered)
      {
        setTimeout(function(){ $('input', form).trigger('change', [true]); }, 1);
      }
    });
  • FF: When a field has focus the text might appear green, this is a bug with FF rendering a work around is applying a background color to the .watermark element.
Comment by jrudd...@gmail.com, Apr 23, 2010

This watermark plugin beats all the other ones.

Comment by dunnlead...@gmail.com, May 19, 2010

Thank you so much! Dunn.

Comment by oferbara...@gmail.com, Jul 20, 2010

doesn't work for me, i'd appreciate a more detailed example writing 'input#email' is not clear weather 'email' is the name or id of the input or if 'input#email' is the name. giving instructions should be with a thorough example.

thanks.

Comment by scorcher...@gmail.com, Jul 21, 2010

Looks great, but for whatever reason when I go to post the form, all the watermarked fields don't appear as form elements any more. I'm not sure why, but I don't have time to debug the plugin. Need to punt on it. Sigh.

Comment by michal.f...@gmail.com, Aug 25, 2010

this works beautifully. however, I'm having an issue with Google Chrome (could be with other browsers, haven't checked yet):

- when the browser autofills the form which uses .watermark plugin, the watermarks stay in place, yet under them, the auto-filled text appears as well, creating an unreadable mashup

Comment by red...@gmail.com, Sep 6, 2010

Hi Mario, how are you? and thank you very much for this lovely plugin. I have now 2 small problems and hope you can help me solve them.

1- how can I have the text inside the input box bold? i tried the property font-weight in the css file but didn't work :(

2- watermark is not positioned well in this page: http://moroccan-arts.co.uk/test-index-watermark.php in the search engine and also when you hover "Account".

Thanks a lot for your help

Comment by razzari, Sep 15, 2010

Hey, I've been researching watermark/label plugins, and this one beats all others, in that the interaction is very polished and most side effects are taken into account (autocomplete, passwords).

Would be 100% good if you could use standard LABEL elements instead of title attributes, in a truer progressive enhancement style.

Comment by justin.c...@gmail.com, Oct 12, 2010

As mentioned above. The watermark doesn't hide itself if the server sets the value of a textbox.

Other than that its pretty easy to use and no other problems.

Comment by nick.alb...@gmail.com, Nov 10, 2010

Is anyone having an issue with this plug-in and IE7/8? Once focus is lost on the text-boxes, the watermark no longer appears.

Comment by scottall...@gmail.com, Nov 20, 2010

It appears defaults does not work with fallback: $.watermarker.setDefaults({fallback: true});

which is a shame since now I have to duplicate all watermarks... the jQuery object method does work with fallback:true but then REQUIREs watermark text.

I also had to add these css rules to get this to work with input elements that are formatted even a tiny bit:

.watermark_container {

width: 100%;
} .watermark {
z-index: 2;
}

Comment by robertbr...@web.de, Feb 21, 2011

I like it. But I need to handle the input field's click event. It looks like whatever shows the watermark blocks the event from the input field. Is there a way around this?

Comment by project member mario.es...@gmail.com, Mar 15, 2011

Any bugs please report in the issues tab: http://code.google.com/p/jq-watermark/issues/list


Sign in to add a comment
Powered by Google Project Hosting