Input Date readOnly attribute

Definition and usage

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

You cannot modify the read-only field. 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:Propriedade readonly do <input> do HTML

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 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 true,caso contrário, retorna false.

Suporte do navegador

Os números na tabela indicam a versão do navegador que suporta plenamente essa propriedade.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Suporte 10.0 Suporte Suporte Suporte

Atenção:O elemento <input type="date"> não exibe nenhum campo de data ou calendário em versões do IE11 ou anteriores.