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.

leepowers
  • 37,828
  • 23
  • 98
  • 129

1 Answers1

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.

Elle H
  • 11,837
  • 7
  • 39
  • 42
  • Did something similar with jquery using `prependTo` for a new field with the correct type while removing the old field. – leepowers Jan 01 '10 at 05:13