Input Month value Attribute

Definition and Usage

value Sets or returns the value of the month field's value attribute.

The HTML value attribute specifies the month and year of the month field.

See also:

HTML Reference Manual:Propriedade value do <input> em HTML

Example

Example 1

Set the month and year of the month field:

document.getElementById("myMonth").value = "2023-06";

Try it yourself

Example 2

Get the month and year of the month field:

var x = document.getElementById("myMonth").value;

Try it yourself

Example 3

An example showing the difference between the defaultValue and value attributes:

var x = document.getElementById("myMonth");
var defaultVal = x.defaultValue;
var currentVal = x.value;

Try it yourself

Syntax

Return the value attribute:

monthObject.value

Set the value attribute:

monthObject.value = YYYY-MM

Attribute value

Value Description
YYYY-MM

Define the month and year.

Descrição do componente:

  • YYYY - Ano (por exemplo, 2023)
  • MM - Mês (por exemplo, 06 para junho)

Detalhes técnicos

Retorno: Valor de string, que representa o mês e o ano do campo do mês.

Suporte ao navegador

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

Atenção:O elemento <input type="month"> não exibe nenhum campo de data ou calendário no Firefox.