Javascript Reference - HTML DOM Input DatetimeLocal disabled Property








The disabled property disables or enables a local datetime field.

Browser Support

disabled Yes Yes Yes Yes Yes

Syntax

Return the disabled property.

var v = datetimelocalObject.disabled 

Set the disabled property.

datetimelocalObject.disabled=true|false

Property Values

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




Return Value

A Boolean type value, true if the local datetime field is disabled, otherwise returns false.

Example

The following code shows how to get if a local datetime field is disabled.


<!DOCTYPE html>
<html>
<body>
<input type="datetime-local" id="myLocalDate" disabled>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--from w  w w.j  a va2  s .com-->
<script>
function myFunction() {
    var x = document.getElementById("myLocalDate").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 local datetime field.


<!DOCTYPE html>
<html>
<body>
<!-- w  w  w .  j av  a2s.  c om-->
<input type="datetime-local" id="myLocalDate"><br><br>

<button onclick="disableBtn()">Disable Local Datetime Field</button>
<button onclick="enableBtn()">Enable Local Datetime Field</button>

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

</body>
</html>

The code above is rendered as follows: