Javascript Reference - HTML DOM Input DatetimeLocal readOnly Property








The readOnly property sets or gets whether a local datetime field should be read-only.

Browser Support

readOnly Yes No No Yes Yes

Syntax

Return the readOnly property.

var v = datetimelocalObject.readOnly

Set the readOnly property.

datetimelocalObject.readOnly=true|false

Property Values

Value Description
true|false Set whether a local datetime field should be read-only
  • true - The local datetime field is read-only
  • false - Default. The local datetime field is not read-only




Return Value

A Boolean type value, true if the local datetime field is read-only, otherwise false.

Example

The following code shows how to get if a local datetime field is read-only.


<!DOCTYPE html>
<html>
<body>
<input type="datetime-local" id="myLocalDate" readonly>
<button onclick="myFunction()">test</button>
<!--from   ww  w. java 2 s .c  o  m-->
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myLocalDate").readOnly;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to set a local datetime field to read-only.


<!DOCTYPE html>
<html>
<body>
<input type="datetime-local" id="myLocalDate">
<button onclick="myFunction()">test</button>
<!--from  w w w. j  av  a  2  s. com-->
<p id="demo"></p>

<script>
function myFunction() {
    document.getElementById("myLocalDate").readOnly = true;
}
</script>

</body>
</html>

The code above is rendered as follows: