Search code examples
javascriptjquerybrowserpasswords

"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.

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.


Solution

  • 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