dexter
dexter

Reputation: 7213

Change TextBox TextMode with jQuery

I was wondering if someone knew the best way to switch from using the

    myTextBox.TextMode = TextBoxMode.Password;

to

  myTextBox.TextMode = TextBoxMode.SingleLine;

using client code and jQuery. I will have to do it on focus, along with deleting the whole text content of the textbox onFocus event.

Upvotes: 1

Views: 5238

Answers (3)

Richard Dalton
Richard Dalton

Reputation: 35793

I don't think you can. Best thing to do is have two text boxes and then hide one on focus and show the other then focus it manually.

$('input:password').focus(function() {
     $(this).hide();
     $(this).siblings('input:text').show().focus();
});

This assumes they are both in the same container and the text box is hidden to start with.

Upvotes: 1

ThiefMaster
ThiefMaster

Reputation: 318598

$('#idOfYourTextbox').attr('type', 'text');

However, you cannot change the type of type="password" fields in IE (yay for useless "security" features).

Upvotes: 4

Michiel Overeem
Michiel Overeem

Reputation: 3992

These webcontrols render completly different: the TextBox with mode SingleLine renders as an an input element with type=text, TextMode.Password changes the rendering to an input element with type=password.

So although in asp.net it is a single property, in jquery you will have to change the attribute type:

$('input.someclass').attr('type','password');

There are however some security limitations. See also this question.

If you also would like to change to TextMode.Multiline, you will have to change the input element to a textarea element.

Upvotes: 1

Related Questions