Input Date readOnly attribute

Definition and usage

readOnly Attribute to set or return whether the date field should be read-only.

You cannot modify a read-only field. However, users can select it, highlight it, and copy text from it.

This property reflects the HTML readonly attribute.

Tip:If you want to prevent users from interacting with this field, use disabled attribute.

See also:

HTML Reference Manual:Sifat readonly untuk <input> HTML

Example

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 attribute:

inputdateObject.readOnly

Set readOnly attribute:

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, if the date field is read-only, it returns trueatau kembalikan false.

Dukungan pelayar

Angka di dalam jadual menunjukkan versi paling awal yang mendukung sifat ini.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Dukungan 10.0 Dukungan Dukungan Dukungan

Perhatian:Elemen <input type="date"> tidak menunjukkan mana-mana medan tarikh/kalender di IE11 dan versi sebelumnya.