Show or Hide password input field using JavaScript

<form method="post" action="login.php">
  	<div class="input-group">
  		<label>Password</label>
  		<input id="myPass" type="password" name="password">
		<input type="checkbox" onclick="showPassword()">Show Password
  	</div>
</form>
<script>
	function showPassword() {
	  var x = document.getElementById("myPass");
	  if (x.type === "password") {
		x.type = "text";
	  } else {
		x.type = "password";
	  }
	}
</script>  

Leave a Reply