HTML DOM Input Password type property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Input password type property is associated with the input element having its type=”password”. It will always return password for the input password element.

Syntax

Following is the syntax for password type property −

passwordObject.type

Example

Let us look at an example for the Input password type property −

 Live Demo

<!DOCTYPE html>
<html>
<body>
<h1>password type property</h1>
PASSWORD: <input type="password" id="PASS1">
<p>Get the above element type by clicking the below button</p>
<button onclick="getType()">Get Type</button>
<p id="Sample"></p>
<script>
   function getType() {
      var t = document.getElementById("PASS1").type;
      document.getElementById("Sample").innerHTML = "The type for the input field is : "+t;
   }
</script>
</body>
</html>

Output

This will produce the following output −

On clicking the “Get Type” button −

In the above example −

We have created an input field with type password and its id set to “PASS1”.

PASSWORD: <input type="password" id="PASS1">

We have then created the “Get Type” button that will execute the getType() method when clicked by the user −

<button onclick="getType()">Get Type</button>

The getType() method gets the input element using the getElementById() method and assigns its type attribute value to variable t. This variable is then displayed in the paragraph with id “Sample” using its innerHTML property −

function getType() {
   var t = document.getElementById("PASS1").type;
   document.getElementById("Sample").innerHTML = "The type for the input field is : "+t;
}
raja
Updated on 22-Aug-2019 10:39:46

Advertisements