Show and hide password

Posted in: javascript by musiitwa joseph 2015-02-21 at 14:07:06

image for Show and hide password Using javascript just change just change type from password to text when the user checks the checkbox and do the reverse on when unchecked.

function _(x){
return document.getElementById(x);
function show_password(){
var pass = _("password");
var checkBox = _("password_controller");

(checkBox.checked == true)? pass.type = "text" : pass.type = "password";//ternary operator, its equivalent to an if else


<div class="container">
<br /><br />
Enter password:<br />
<input type="password" value="" name="" id="password" /><br />
<input type="checkbox" value="sdf" id="password_controller" onClick="return show_password();"> Show password

Related Posts