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

1
  • 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? Commented May 7, 2011 at 12:09

3 Answers 3

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.

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

Comments

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.

2 Comments

it will not work in IE (pre-IE9) though .. you need to replace the field.
yes your right it would be more efficient to add two fields, thanks
0

Do this:

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

Hope this works.

Comments

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.