3

i have a login component and within it the password field has a textmode of singlline

what i am trying to do is on focus the textmode will change to password

i tried this :

$(function () {
   $(".PassTextBox").focus(function (pas) {
       $(".PassTextBox").attr("TextMode", "Password");
   });
});

but it didn't work

using asp.net 3.5 , thanks

Gabriele Petrioli
  • 173,972
  • 30
  • 239
  • 291
Wahtever
  • 3,377
  • 9
  • 41
  • 74
  • 2
    Interesting. Is there a reason why you want to do this on the client side, instead of simply using a `TextBox` control in password mode? – Frédéric Hamidi May 07 '11 at 12:09

3 Answers3

3

Why not display it as a password field from the start ?

If you have to, take a look at How display text in password field

It is not as simple as it seems because IE (before v9) does not allow to dynamically change the type of the textbox, so you will have to actually replace it with another one.

Community
  • 1
  • 1
Gabriele Petrioli
  • 173,972
  • 30
  • 239
  • 291
0

You'll need to change the "type" attribute to password. "TextMode" is an asp.net control attribute, but on the client side it gets turned into an HTML input, which has a type attribute: http://htmlhelp.com/reference/html40/forms/input.html

$(function () {
$(".PassTextBox").focus(function (pas) {
    $(".PassTextBox").attr("Type", "Password");
});
});

UPDATE: After testing this to confirm it works, it appears changing the type may not be supported on all browsers or by jQuery. This answer will give you some more insight. My suggestion is to put two fields on the form and dynamically show/hide them to give the same effect.

Community
  • 1
  • 1
Ken Pespisa
  • 21,026
  • 3
  • 53
  • 61
0

Do this:

$(function () {
  $(".PassTextBox").focus(function (pas) {
    $(".PassTextBox").attr("type", "password");
  });
});

Hope this works.

Edgar Villegas Alvarado
  • 17,527
  • 1
  • 39
  • 59