Javascript Reference - HTML DOM Keygen disabled Property








The disabled property disables or enables a keygen field.

Browser Support

Keygen disabled Yes No Yes Yes Yes

Syntax

Return the disabled property.

keygenObject.disabled 

Set the disabled property.

keygenObject.disabled=true|false 

Property Values

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




Return Value

A Boolean type value, true if the keygen field is disabled, otherwise false.

Example

The following code shows how to check if a keygen field is disabled.


<!DOCTYPE html>
<html>
<body>
Encryption: <keygen id="myKeygen" name="security" disabled>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--  w  w w .jav a  2s. c  om-->
    var x = document.getElementById("myKeygen").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 keygen field.


<!DOCTYPE html>
<html>
<body>
<!--from w ww .  java  2  s .  c  o m-->
<form action="demo_keygen.asp" method="get">
  Username: <input type="text" name="usr_name">
  Encryption: <keygen id="myKeygen" name="security">
  <input type="submit">
</form><br>
<button onclick="disableKey()">Disable Keygen field</button>
<button onclick="undisableKey()">Enable Keygen field</button>

<script>
function disableKey() {
    document.getElementById("myKeygen").disabled = true;
}

function undisableKey() {
    document.getElementById("myKeygen").disabled = false;
}
</script>

</body>
</html>

The code above is rendered as follows: