Javascript Reference - HTML DOM Input Month readOnly Property








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

Browser Support

readOnly Yes No No Yes Yes

Syntax

Return the readOnly property.

var v = monthObject.readOnly

Set the readOnly property.

monthObject.readOnly=true|false

Property Values

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




Return Value

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

Example

The following code shows how to check if a month field is read-only.


<!DOCTYPE html>
<html>
<body>
<input type="month" id="myMonth" readonly>
<button onclick="myFunction()">test</button>
<!--from   w  ww .  j a v  a  2s.  c  o m-->
<p id="demo"></p>

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


<!DOCTYPE html>
<html>
<body>
<input type="month" id="myMonth">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--   w w w.j a  v a2  s.com-->
    document.getElementById("myMonth").readOnly = true;
}
</script>
</body>
</html>

The code above is rendered as follows: