The readOnly
property sets or gets whether a date field is read-only.
readOnly |
Yes | No | No | Yes | Yes |
Return the readOnly property.
var v = inputdateObject.readOnly
Set the readOnly property.
inputdateObject.readOnly=true|false
Value | Description |
---|---|
true|false | Set whether a date field should be read-only
|
A Boolean type value, true if the date field is read-only, otherwise false.
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:
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: