I’ve got a sign up form that requires the user to enter their email and password, both are in two separate text boxes. I want to provide a button that the user can click so that the password (which is masked) will appear in a popup when the user clicks the button.
Currently my JavaScript code for this is as follows:
function toggleShowPassword() { var button = $get('PASSWORD_TEXTBOX_ID'); var password; if (button) { password = button.value; alert(password); button.value = password; } }
The problem is that every time the user clicks the button, the password is cleared in both Firefox and IE. I want them to be able to see their password in clear text to verify without having to retype their password.
My questions are:
-
Why does the password field keep getting reset with each button click?
-
How can I make it so the password field is NOT cleared once the user has seen his/her password in clear text?
I did a quick example up of a working version:
The key is that the input is of type button and not submit. I used the prototype library for retrieving the element by ID.