Input Month readOnly Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Month

Description

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

This property reflects the HTML readonly attribute.

Set the readOnly property with the following Values

Value Description
true|false Sets 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, returns true if the month field is read-only, otherwise it returns false

The following code shows how to Set a month field to read-only:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="month" id="myMonth" readonly>

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {//from w  ww. ja  v a 2  s .co  m
    document.getElementById("myMonth").readOnly = true;
    document.getElementById("demo").innerHTML = "changed";
}
</script>
</body>
</html>

Related Tutorials