Javascript Reference - HTML DOM Input Week readOnly Property








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

Browser Support

readOnly Yes No No Yes Yes

Syntax

Return the readOnly property.

var v = weekObject.readOnly

Set the readOnly property.

weekObject.readOnly=true|false

Property Values

Value Description
true|false Specifies whether or not a week field should be read-only
  • true - The week field is read-only
  • false - Default. The week field is not read-only




Return Value

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

Example

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


<!DOCTYPE html>
<html>
<body>
<!--from  w w w  .j  a va  2s. com-->
<input type="week" id="myWeek" readonly>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myWeek").readOnly;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to change a week field to read-only.


<!DOCTYPE html>
<html>
<body>
<input type="week" id="myWeek">
<button onclick="myFunction()">test</button>
<!--from  www .j  a v a2 s.  co  m-->
<p id="demo"></p>

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

</body>
</html>

The code above is rendered as follows: