This.type = 'password' doesn't work in IE, but all other browsers it does

I have an input field that is set to type = "text" by default so that it can display the word Password. I have the following to change it to a password field when the user selects it, which works fine in any browser I've tried other than Internet Explorer.

onfocus="this.type='password';"

      

How do I make this work in IE?

+2


source to share


3 answers


IE does not like to dynamically change the element type, one solution might be to replace the entire element. However, I would advise you to use an input type password so that no users can use the same functionality and live without a watermark.



+6


source


What effect are you trying to achieve? Do you want the initial password to be visible, but when they go to enter a new one, is it hidden? If so, you can simply replace the element with a password by copying the value.



+1


source


You are better off using a <label> with the text "password" rather than displaying it inside the control itself. You can make the shortcut as it is inside the textbox using css. List Apart has a good article on things like this: http://www.alistapart.com/articles/makingcompactformsmoreaccessible/

+1


source







All Articles