Suraj
Suraj

Reputation: 930

Change Input val. and type using jQuery

<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"...

Upvotes: 0

Views: 720

Answers (1)

EMMERICH
EMMERICH

Reputation: 3474

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

Upvotes: 1

Related Questions