Input Date readOnly attribute

Definition and usage

readOnly Property sets or returns whether the date field should be read-only.

Read-only fields cannot be modified. However, users can select it, highlight it, and copy text from it.

This property reflects the HTML readonly attribute.

Tip:To prevent users from interacting with this field, use disabled attribute.

See also:

HTML reference manual:HTML <input> readonly attribute

Instance

Example 1

Set the date field to read-only:

document.getElementById("myDate").readOnly = true;

Try it yourself

Example 2

Check if the date field is read-only:

var x = document.getElementById("myDate").readOnly;

Try it yourself

Syntax

Return readOnly property:

inputdateObject.readOnly

Set readOnly property:

inputdateObject.readOnly = true|false

Attribute value

Value Description
true|false

Specify whether the date field should be read-only

  • true - The date field is read-only
  • false - Default. The date field is not read-only

Technical details

Return value: Boolean value, returns if the date field is read-only true, otherwise 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="date"> element does not display any date field/calendar in IE11 and earlier versions.