Javascript Reference - HTML DOM Input Time readOnly Property








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

Browser Support

readOnly Yes No No Yes Yes

Syntax

Return the readOnly property.

var v = timeObject.readOnly

Set the readOnly property.

timeObject.readOnly=true|false

Property Values

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




Return Value

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

Example

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


<!DOCTYPE html>
<html>
<body>
<!--  w w  w  . j ava 2 s.  c om-->
Time: <input type="time" id="myTime" readonly>
<button onclick="myFunction()">test</button>
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myTime").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 time field to read-only.


<!DOCTYPE html>
<html>
<body>
Time: <input type="time" id="myTime">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--  w  w  w  .j  av  a  2  s  .  c  o m-->
<script>
function myFunction() {
    document.getElementById("myTime").readOnly = true;
}
</script>

</body>
</html>

The code above is rendered as follows: