Set a datetime field to read-only:
document.getElementById("myDatetime").readOnly = true;
Click the button to set the datetime field to read-only.
<!DOCTYPE html> <html> <body> Birthday: <input type="datetime" id="myDatetime"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w ww. j a v a 2s. c om*/ document.getElementById("myDatetime").readOnly = true; } </script> </body> </html>
The readOnly
property sets or gets whether a datetime field should be read-only.
This property mirrors the HTML readonly attribute.
The readOnly
property accepts and returns a boolean type value.
Property Values
Value | Description |
---|---|
true | The datetime field is read-only |
false | Default. The datetime field is not read-only |