Input Datetime readOnly Attribute
Example
Set the datetime field to read-only:
document.getElementById("myDatetime").readOnly = true;
Output result:
Definition and Usage
The readOnly attribute is used to set or return whether the datetime field is read-only.
Read-only fields cannot be modified. However, their content can be copied.
This attribute reflects the HTML readonly attribute.
Tip: To ensure the accuracy of form data, you can use the disabled attribute instead.
Browser Support
All major browsers support the readOnly attribute.
Note: Internet Explorer, Firefox, Opera 15 (and later versions), or Chrome support the <input> element with type="datetime".
Syntax
Return the readOnly attribute:
Set the readOnly attribute:
Attribute Values
| Value | Description |
|---|---|
| true|false | Describes whether the datetime field is read-only<br>true - The datetime field is read-only<br>false - Default. The datetime field is not read-only |
Technical Details
| Return Value: | Boolean, returns true if the datetime field is read-only, otherwise returns false. | | --- | --- |
More Examples
Example
Check if the datetime field is read-only:
var x = document.getElementById("myDatetime").readOnly;
true
Related Articles
HTML Reference: HTML <input> readonly Attribute