Javascript DOM HTML Input Password placeholder Property get

Introduction

Get the placeholder text of a password field:

var x = document.getElementById("myPassword").placeholder;

Click the button to display the placeholder text of the password field.

View in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {/*w w  w  .jav a 2 s  . c  o m*/
  var x = document.getElementById("myPsw").placeholder;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related