How To Show/hide Text From Input Field [type=”password”]

To do that select the input field from any selector in javascript and then apply type attribute and change its type attribute’s value to text.

<!DOCTYPE html>
<html>
<head>
  <title>Show & Hide password</title>
</head>
<body>

  <input type="password" id="pwd" />
  <input type="checkbox" id="cbox" />

  <script>

    var c_box=document.getElementById("cbox");
    c_box.onclick=function()
    {
      if(c_box.checked==true)
      {
      var password=document.getElementById("pwd");
      password.type="text";
      }
      else
      {
        var password=document.getElementById("pwd");
        password.type="password";
      }
    }

  </script>
</body>
</html>

Leave a Comment