0
<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
  • 1
    Using common courtesy: OnAskQuestion - show community what code you have tried already. Commented Oct 21, 2010 at 15:57

1 Answer 1

1
$('#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.

Sign up to request clarification or add additional context in comments.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.