Javascript DOM HTML Input Month readOnly Property set

Introduction

Set a month field to read-only:

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

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

input elements with type=month is not supported in Firefox.</p>

View in separate window

<!DOCTYPE html>
<html>
<body>

<input type="month" id="myMonth">
<button onclick="myFunction()">Test</button>
<script>
function myFunction() {//from   w w  w . java  2  s  .  c om
  document.getElementById("myMonth").readOnly = true;
}
</script>

</body>
</html>

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

This property mirrors the HTML readonly attribute.

The <input type="month"> element is not supported in Firefox.

The readOnly property accepts and returns a boolean type value.

Value Description
true The month field is read-only
falseDefault. The month field is not read-only

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




PreviousNext

Related