Javascript Reference - HTML DOM Input Datetime disabled Property








The disabled property enables or disables a datetime field.

Browser Support

disabled No No No No No

Syntax

Return the disabled property.

var v = datetimeObject.disabled 

Set the disabled property.

datetimeObject.disabled=true|false

Property Values

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




Return Value

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

Example

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


<!DOCTYPE html>
<html>
<body>
<!--from www  . j ava  2  s . c  o m-->
<input type="datetime" id="myDatetime" disabled>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myDatetime").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 datetime field.


<!DOCTYPE html>
<html>
<body>
<!--   w  w  w.  j av  a2 s . c om-->
<input type="datetime" id="myDatetime"><br><br>

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

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

</body>
</html>

The code above is rendered as follows: