Javascript Reference - HTML DOM Input Date readOnly Property








The readOnly property sets or gets whether a date field is read-only.

Browser Support

readOnly Yes No No Yes Yes

Syntax

Return the readOnly property.

var v = inputdateObject.readOnly

Set the readOnly property.

inputdateObject.readOnly=true|false

Property Values

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




Return Value

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

Example

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


<!DOCTYPE html>
<html>
<body>
<input type="date" id="myDate" readonly>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from   w ww. j  a  va2  s.  c o m-->
    var x = document.getElementById("myDate").readOnly;
    document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to use mark a date field to be read-only.


<!DOCTYPE html>
<html>
<body>
Birthday: <input type="date" id="myDate">
<button onclick="myFunction()">test</button>
<!--from w  w  w.  ja v  a 2  s.  co m-->
<p id="demo"></p>

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

</body>
</html>

The code above is rendered as follows: