Fiddle : http://jsfiddle.net/WqUZX/
There is no way to do this. Let's say *
is a character that "hides" a password. When the inputs that are characteristic, the script cannot "remember" it. Another problem may occur when the user presses the delete
or backspace
inside the line. Inserting a line in an input field can also cause problems.
Of course, you can implement such a function using selectionStart
, selectionEnd
and a bunch of key event listeners. However, this approach is not waterproof.
The nearest reliable solution changes type
to text
for focus and back to password
for blur.
$("#user_password").focus(function(){ this.type = "text"; }).blur(function(){ this.type = "password"; })
Alternatively, you can use mouseover
to display the password. Thus, the user can easily choose whether he wants to use the show-password function or not.
Rob w source share