Javascript DOM HTML Input Password maxLength Property get

Introduction

Get the maximum number of characters allowed in a specific password field:

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

Click the button to display the value of the maxlength attribute in the password field.

View in separate window

<!DOCTYPE html>
<html>
<body>

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

<script>
function myFunction() {/*  w ww .j av a2 s . c  om*/
  var x = document.getElementById("myPsw").maxLength;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The maxLength property sets or gets the value of the maxlength attribute of a password field.

The maxlength attribute sets the maximum number of characters allowed in a password field.

To set or return the width of a password field, in number of characters, use the size property.

The maxLength property accepts and returns an integer.




PreviousNext

Related