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

Date Published: 31/08/2020 Published By: JaiSchool

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>

Publish A Comment

Leave a Reply

Your email address will not be published. Required fields are marked *