Javascript Reference - HTML DOM Input Password disabled Property








The disabled property disables or enables a password field.

Browser Support

The disabled property is supported in all major browsers.

disabled Yes Yes Yes Yes Yes

Syntax

Return the disabled property.

var v = passwordObject.disabled 

Set the disabled property.

passwordObject.disabled=true|false 

Property Values

Value Description
true|false Disable or enable a password field.
  • true - The password field is disabled
  • false - Default. The password field is not disabled




Return Value

A Boolean type value, returns true if the password field is disabled, otherwise it returns false.

Example

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:





Example 2

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:

Example 3

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: