The disabled
property disables or enables a password field.
The disabled property is supported in all major browsers.
disabled |
Yes | Yes | Yes | Yes | Yes |
Return the disabled property.
var v = passwordObject.disabled
Set the disabled property.
passwordObject.disabled=true|false
Value | Description |
---|---|
true|false | Disable or enable a password field.
|
A Boolean type value, returns true if the password field is disabled, otherwise it returns false.
The following code shows how to check if a password field is disabled.
<!DOCTYPE html>
<html>
<body>
Password: <input type="password" id="myPsw">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--from w ww . j a va 2 s .co m-->
<script>
function myFunction() {
var x = document.getElementById("myPsw").disabled;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to disable and enable a password field.
<!DOCTYPE html>
<html>
<body>
<!-- ww w . j a va 2 s . co m-->
<form>
Username: <input type="text" id="usrname"><br>
Password: <input type="password" id="myPsw">
</form><br>
<button onclick="disablePsw()">Disable Password field</button>
<button onclick="enablePsw()">Enable Password field</button>
<script>
function disablePsw() {
document.getElementById("myPsw").disabled = true;
}
function enablePsw() {
document.getElementById("myPsw").disabled = false;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to disable a password field.
<!DOCTYPE html>
<html>
<body>
<!--from ww w . j av a 2 s . com-->
Password: <input type="password" id="myPsw">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myPsw").disabled = true;
}
</script>
</body>
</html>
The code above is rendered as follows: