Password readOnlyProperty
Password Object
Definition and Usage
The readOnly property sets or returns whether the password field is read-only.
Read-only fields cannot be modified. However, the user can select it and copy the text.
Syntax
Set the readOnly property:
passwordObject.readOnly=true|false
Return the readOnly property:
passwordObject.readOnly
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the readOnly property
Example
Example
The following example sets the password field to read-only:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function setResult(){
document.getElementById("pwd").readOnly=true;
}
</script>
</head>
<body>
<form>
Password: <input type="password" id="pwd">
</form>
<button type="button" onclick="setResult()">Set read-only</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function setResult(){
document.getElementById("pwd").readOnly=true;
}
</script>
</head>
<body>
<form>
Password: <input type="password" id="pwd">
</form>
<button type="button" onclick="setResult()">Set read-only</button>
</body>
</html>
Try it Yourself »
Password Object Other Extensions