Set a password field to read-only:
document.getElementById("myPsw").readOnly = true;
Click the button to set the password field to read-only.
<!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 |
false | Default. The password field is changeable |
The readOnly property returns true if the password field is read-only, otherwise it returns false.