I am trying to get this simple script to work. Basically, when a user clicks on the Show link, it will display the password in the password text box and hide it when it is clicked again. I have searched for solutions but couldn't find anything for what I need. Here is the code:
JavaScript
function toggle_password(target){
var tag = getElementById(target);
var tag2 = getElementById("showhide");
if (tag2.innerHTML == 'Show'){
tag.setAttribute('type', 'text');
tag2.innerHTML = 'Hide';
}
else{
tag.setAttribute('type', 'password');
tag2.innerHTML = 'Show';
}
}
HTML
<label for="pwd0">Password:</label>
<input type="password" value="####" name="password" id="pwd0" />
<a href="#" onclick="toggle_password('pwd0');" id="showhide">Show</a>
When I click the link, nothing happens. I have tested this without using the if statement too and still did nothing.
Its really easy to achieve...I found this blog post which describes the way of doing it with a few lines of code. I think its not a good practice to keep an option like this because passwords must be treated seriously.
here is the code from that page; it uses the same approach as you described. but uses a check-box.and practically i have seen what he points out in oss' like linux. they don't even leave a trace of the password with an asterisk.(but the gui thing does, don't know they really care about pw privacy or they find it difficult to do it in command line ;-) )
If we make a textbox type as
"passowrd"
then chars are not shown and but when we make a text-box type"text"
chars are shown as we type.Hence the logic is very simple. We can change the type of any HTML element by
"setAttribute(type,newvalue)"
function of JavaScript.A complete code example can be seen on below link:
http://www.tutor4web.com/javascript/how-to-show-password-as-text-with-checkbox-using-javascript/
You could use inline script for a simple implementation of show/hide password.
Don't change input type, change text size. Make it very small for Hide.
Because of security reasons you can't change the type of an input element. You have to replace the entire element with a new one.
http://www.voidtricks.com/password-show-hide-checkbox-click/ This is a simple tutorial to show a password in a input box when a checkbox is checked and hide it when the checkbox is unchecked using jQuery.
Javascript
HTML *
* We have a password input field with the class “password” and a checkbox with the id “showHide”
Easy solution for show / hide password using checkboxes, and this is noob level just copy/paste. DONE !!! ;-)