views:

354

answers:

5
<input type="text" value="useraname" />
<input type="password" value="password" />

I'm using jQuery to make the inline labels disappear on click/focus. Password shows bulls as usual, but I wonder if its possible somehow to show "Password" label as text (instead of ••••) inside the password field?

Edited to add: I want the user-typed password to be hidden ofcourse!.

Thanks

A: 

If you make the input type="textbox" you'll be able to see the password.

Galen
Ofcourse, but then the password will be visible too. I just need the label to be text.
Nimbuz
im not sure what you mean by that.
Galen
As soon as the box receives focus, change it to a type="password" . Presumably you've already got code that clears out the value when the box is focused, so just add it there.The plugin route might be better though.
McPherrinM
@WaffleMatt: Great idea, but I'm not sure how to do that, can someone help with the code? Many thanks!
Nimbuz
+1  A: 

There are plugins for that. See labelify for example

Edit: this one handle passwords correctly

RC
A: 

I think you'd need to dynamically overlay an <input type="text"> on top of the password field to do this.

cxfx
+1  A: 

Check out the code below. Just append addPassClear("Password") to any input element that you want this functionality for.

$(function() {
$.fn.addPassClear =
function(text)
{
  return $(this).each(
  function()
  {
    $(this).focus(function(event){$(this).passFocusize(text); $(this).select(); });
    $(this).blur(function(event){$(this).passBlurize(text); });
  });
}
$.fn.passFocusize =
function(text)
{
  return $(this).each(
  function()
  {
    if ($(this).val()==text && $(this).attr("type")=="text")
    {
      $(this).val("");
      this.type="password";
    }
  });
};
$.fn.passBlurize =
function(text)
{
  return $(this).each(
  function()
  {
    if ($(this).val()=="")
    {
      $(this).val(text);
      this.type="text";
    }
  });
};
};
Dan Loewenherz
A: 

why all that long script for? that jus a simple task which can be done with a half line of code :

<input type='text' onclick="this.type='password',value=''" class='watever' value='password'..etc  

cheers

Nader Rouinia