Javascript Reference - HTML DOM Input Month disabled Property








The disabled property disables or enables a month field.

Browser Support

disabled Yes Yes Yes Yes Yes

Syntax

Return the disabled property.

var v = monthObject.disabled 

Set the disabled property.

monthObject.disabled=true|false

Property Values

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




Return Value

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

Example

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


<!DOCTYPE html>
<html>
<body>
<!-- ww  w .  j  av a 2s  .  c o  m-->
<input type="month" id="myMonth" disabled>
<button onclick="myFunction()">test</button>
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myMonth").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 month field.


<!DOCTYPE html>
<html>
<body>
<!--  w  w  w .  ja v a  2  s  .c  om-->
<input type="month" id="myMonth"><br><br>

<button onclick="disableBtn()">Disable Month Field</button>
<button onclick="enableBtn()">Enabled Month Field</button>

<script>
function disableBtn() {
    document.getElementById("myMonth").disabled = true;
}
function enableBtn() {
    document.getElementById("myMonth").disabled = false;
}
</script>

</body>
</html>

The code above is rendered as follows: