Input DatetimeLocal readOnly Attribute
Example
Set the local datetime field to read-only:
document.getElementById("myLocalDate").readOnly = true;
Output result:
Definition and Usage
The readOnly attribute is used to set or return whether the local datetime field is read-only.
A read-only field cannot be modified. However, its 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
The readOnly property is supported by all major browsers.
Note: The <input type="datetime-local"> element is not supported by Internet Explorer or Firefox browsers.
Syntax
Return the readOnly attribute:
Set the readOnly attribute:
Attribute Values
| Value | Description |
|---|---|
| true|false | Describes whether the local datetime field is read-only<br>true - The local datetime field is read-only<br>false - Default. The local datetime field is not read-only |
Technical Details
| Return Value: | Boolean, returns true if the local datetime field is read-only, otherwise returns false. | | --- | --- |
More Examples
Example
Check if the local datetime field is read-only:
var x = document.getElementById("myLocalDate").readOnly;
true
Related Pages
HTML Reference: HTML <input> readonly Attribute