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