Javascript DOM HTML Input Password readOnly Property set

Introduction

Set a password field to read-only:

document.getElementById("myPsw").readOnly = true;

Click the button to set the password field to read-only.

View in separate window

<!DOCTYPE html>
<html>
<body>

Password: <input type="password" id="myPsw">
<button onclick="myFunction()">Set read-only</button>

<script>
function myFunction() {/*w  w  w.ja  v a2s.c  o  m*/
  document.getElementById("myPsw").readOnly = true;
}
</script>

</body>
</html>

The readOnly property sets or gets whether a password field is read-only.

A read-only field cannot be modified.

The readOnly property accepts and returns a boolean type value.

Value Description
true The password field is read-only
falseDefault. The password field is changeable

The readOnly property returns true if the password field is read-only, otherwise it returns false.




PreviousNext

Related