views:

26

answers:

1
<input name="myusername" type="text" id="u" class="blackle u" value="Username..." />
<input name="mypassword" type="text" id="p" class="blackle p" value="Password..." />

Using jQuery...
Onfocus - if #u has val "Username..." then change it to "" (blank)
OnBlur - if #u has val "" (blank) then change it back to "Username..."


Onfocus - if #p has val "Password..." then change it to "" (blank) ; additionally here the val of attribute type should be changed to "password" from "text"...
OnBlur - if #u has val "" (blank) then change it back to "Password..." ; Again the val of type attribute should be changed back to "text" from "password"...

+1  A: 
$('#u').focus(function() {
  if($(this).val() === "Username...") {
    $(this).val("");
  }
}).blur(function() {
  if($(this).val() === "") {
    $(this).val("Username...");
  }
});

Rinse and repeat. The functionality of what you're trying to do looks a lot like the placeholder plugin, though.

EMMERICH
what about the second part? I mean changing the attribute of pwd field
tunetosuraj
.attr("type", "text"); or .attr("type", "password"). I wouldn't do this, though. It's not typical website behaviour.
EMMERICH