The readOnly
property sets or gets if a password field is read-only.
readOnly |
Yes | Yes | Yes | Yes | Yes |
Return the readOnly property.
var v = passwordObject.readOnly
Set the readOnly property.
passwordObject.readOnly=true|false
Value | Description |
---|---|
true|false | Set if a password field should be read-only.
|
A Boolean type value, true if the password field is read-only, otherwise false.
The following code shows how to check if a password field is read-only.
<!DOCTYPE html>
<html>
<body>
<!-- ww w. ja v a 2 s.co m-->
Password:<input type="password" id="myPsw" readonly>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myPsw").readOnly;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to set a password field to read-only.
<!DOCTYPE html>
<html>
<body>
<!-- w w w.j a v a 2 s . c om-->
Password: <input type="password" id="myPsw">
<button onclick="myFunction()">Set read-only</button>
<script>
function myFunction() {
document.getElementById("myPsw").readOnly = true;
}
</script>
</body>
</html>
The code above is rendered as follows: