Javascript Reference - HTML DOM Input Date disabled Property








The disabled property disable or enable a date field.

Browser Support

disabled Yes No No Yes Yes

Syntax

Return the disabled property.

var v = inputdateObject.disabled 

Set the disabled property.

inputdateObject.disabled=true|false

Property Values

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




Return Value

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

Example

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


<!DOCTYPE html>
<html>
<body>
<input type="date" id="myDate" disabled>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!-- w w  w  .  j av  a 2s.c o  m-->
    var x = document.getElementById("myDate").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 enabled a date field.


<!DOCTYPE html>
<html>
<body>
<!--from  ww  w  . j a  va2s  .c o  m-->
<input type="date" id="myDate"><br><br>

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

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

</body>
</html>

The code above is rendered as follows: