Javascript DOM HTML Input DatetimeLocal readOnly Property

Introduction

Set a local datetime field to read-only:

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

Click the button to set the local datetime field to read-only.

View in separate window

<!DOCTYPE html>
<html>
<body>

<input type="datetime-local" id="myLocalDate">
<button onclick="myFunction()">Test</button>
<script>
function myFunction() {/*from  w  w  w.ja  va2  s.  co  m*/
  document.getElementById("myLocalDate").readOnly = true;
}
</script>

</body>
</html>

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

This property mirrors the HTML readonly attribute.

The readOnly property accepts and returns a boolean type value.

Value Description
true The local datetime field is read-only
false Default. The local datetime field is not read-only

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




PreviousNext

Related