2

The following javascript snippet will change the type of an INPUT, for instance from text to password. It's being used to allow users to display their password on-screen when typing it in:

document.save_form.password_confirm.type= 'text';
...
document.save_form.password_confirm.type= 'password';

This works great in FF/Chrome but in IE6/7/8 I'm getting a "This command is not supported" error message.

1 Answer 1

6

Type is read-only in Internet Explorer (at least 6, anyway), so it's just not directly possible. As a workaround, I've had a hidden input field of the type I wanted, then when I need to switch the type, hid the old one and made the other one visible. Not as clean, but unfortunately just changing the type as far as I know isn't possible.

An alternative method would be to use the JavaScript DOM to replace the field with the replaceChild function of a node.

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

1 Comment

Did something similar with jquery using prependTo for a new field with the correct type while removing the old field.

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.