This is what someone on this list gave me about 2 weeks ago:

// the focus / blur functionality of the text input
// fields for the email a friend form.
$('#input.email').bind('focus', function() { 
        // Set the default value if it isn't set 
        if ( !this.defaultValue ) this.defaultValue = this.value; 
        // Check to see if the value is different 
        if ( this.defaultValue && this.defaultValue != this.value ) return; 
        // It isn't, so remove the text from the input 
        this.value = ''; 
}) 
.bind('blur', function() { 
        // If the value is blank, return it to the defaultValue 
        if ( this.value.match(/^\s*$/) ) 
                this.value = this.defaultValue; 
});

-----Original Message-----
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of sperks
Sent: Monday, August 25, 2008 3:26 PM
To: jQuery (English)
Subject: [jQuery] input:empty and remember password


I have a script that displays username and password as background images in
the input fields when the field is empty and they removes it when on focus
(or when there's content left in the field). I then came up against the
issue where if someone's browser populates the input fields after their
browser is asked to remember their password and I end up with both the input
fields being populated and the background showing.  Here's my initial
script:

$(document).ready(function() {
  $('#loginArea').addClass('active');
  $('#loginArea.active input')
    .focus(function() {
      $(this).addClass("nobg");
    })
    .blur(function() {
      if ($(this).val() == '') {
        $(this).addClass("nobg");
      };
   });
});

I tried using
  $('#loginArea.active input:empty').removeClass("nobg");
but FF doesn't add the username/password until after the page has loaded (I
don't know what other browsers are doing), and thus the decision to addClass
is based on empty cells.

Anyone have an idea of how to resolve this one?


Reply via email to