Javascript DOM HTML Input Time readOnly Property

Introduction

Set a time field to read-only:

document.getElementById("myTime").readOnly = true;

Click the button to set the time field to read-only.

View in separate window

<!DOCTYPE html>
<html>
<body>

Time: <input type="time" id="myTime">
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from  www.  j av  a2 s  .c o m*/
  document.getElementById("myTime").readOnly = true;
}
</script>

</body>
</html>

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

A read-only field cannot be modified.

This property mirrors the HTML readonly attribute.

The <input type="time"> element is not supported in Firefox.

The readOnly property accepts and returns a String type value.

Value Description
true The time field is read-only
falseDefault. The time field is not read-only

The readOnly property returns true if the time field is read-only, otherwise it returns false.




PreviousNext

Related