Input Datetime readOnly Attribute
Definition and Usage
readOnly
Sets or returns whether the date-time field should be read-only.
You cannot modify read-only fields. However, users can select, highlight it, and copy text from it.
This property reflects the HTML readonly attribute.
Tip:If you want to prevent users from interacting with the field, use disabled attribute.
See Also:
HTML Reference Manual:HTML <input> readonly Attribute
Example
Example 1
Set the date-time field to read-only:
document.getElementById("myDatetime").readOnly = true;
Example 2
Check if the date-time field is read-only:
var x = document.getElementById("myDatetime").readOnly;
Syntax
Return readOnly attribute:
datetimeObject.readOnly
Set readOnly attribute:
datetimeObject.readOnly = true|false
Attribute Value
Value | Description |
---|---|
true|false |
Specifies whether the date-time field should be read-only
|
Technical Details
Return value: | Boolean value, returned if the date-time field is read-only true If not, return false . |
---|
Browser Support
The numbers in the table indicate the first browser version that fully supports this attribute.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | 10.0 | Support | Support | Support |
Note:The <input type="datetime"> element does not display any date/time field/calendar in any mainstream browser except Safari.