Javascript DOM HTML Input Date readOnly Property set

Introduction

Set a date field to read-only:

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

Birthday: <input type="date" id="myDate">
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from w  w w. j  av  a  2s.  c o  m*/
  document.getElementById("myDate").readOnly = true;
}
</script>

</body>
</html>

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

A read-only field cannot be modified.

This property mirrors the HTML readonly attribute.

The readOnly property accepts and returns a boolean type value.

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

It returns true if the date field is read-only, otherwise it returns false.




PreviousNext

Related