3

I have a problem in that I am using a simple watermark plugin such that it works

jQuery('#selector').Watermark('Watermark text here ...');

The problem is - when I try and use something like

if (jQuery('#selector').val() != "") { //do stuff }

The statement is True because of the watermark. Is there anyway I can somehow "ignore" this watermark value for my If statement ?

Thanks

Tom
  • 31
  • 1

3 Answers3

3
if (jQuery('#selector').val() != "" && jQuery('#selector').val() != "'Watermark text here ...'") { //do stuff }

This only assumes that the watermark text is static across examples. If not then you may need a collection of watermark texts?

dredful
  • 4,378
  • 2
  • 35
  • 54
1

You could ignore the watermark text as well other than empty:

if (jQuery('#selector').val() != "" && jQuery('#selector').val() != "your watermark text")
{
  //do stuff
}
Sarfraz
  • 377,238
  • 77
  • 533
  • 578
  • hmm yeah thanks sarfraz - this is exactly what I'd thought of myself. Just wondering whether there was something I was completely missing here :) +1 for this – Tom Sep 21 '10 at 19:04
0

Similar question here:

Jquery: Is there some way to make val() return an empty string instead of 'undefined' for an empty list?

The gist of the solution in your case would be:

if ((jQuery('#selector').not('.watermark').val()||'') != "") { //do stuff }
Community
  • 1
  • 1
Chris
  • 39,719
  • 45
  • 189
  • 235