Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Show password as text" control

I have a usual login form consisting of two input fields, one for login, one for password. I am currently trying to add a control that will show entered password as plain text, so user can check it for typos.

The problem is that browsers (at least Firefox) do not allow dynamic changing of type attribute of input fields, so I cannot just change type="password" to type="text". Another problem is that browsers do not allow to get value of password field, so I can't create a new input type="text" and set its value to the password's one. I've seen several different approaches to this task, including this one, but they are working only if the password is typed and fail when browser autofills the password.

So, any suggestions to do this are welcome. I am using jQuery.

like image 447
n1313 Avatar asked Sep 05 '09 11:09

n1313


1 Answers

You can do something like this:

<input type="password" id="password">
<input type="checkbox" onchange="document.getElementById('password').type = this.checked ? 'text' : 'password'"> Show password
like image 165
Gumbo Avatar answered Sep 20 '22 15:09

Gumbo