Javascript DOM HTML Input Password type Property get

Introduction

Find out which type of form element the password field is:

var x = document.getElementById("myPsw").type;

Click the button to find out which type of form element the password field is.

View in separate window

<!DOCTYPE html>
<html>
<body>

Password: <input type="password" id="myPsw">
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from  w  w  w  . j  a  v a2 s  . com
  var x = document.getElementById("myPsw").type;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The type property returns which type of form element a password field is.

For a password field, this property will always return "password".




PreviousNext

Related