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:Atributo value del elemento <input> de 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.

Descripción del componente:

  • YYYY - Año (por ejemplo, 2023)
  • MM - Mes (por ejemplo, 06 para junio)

Detalles técnicos

Valor devuelto: Valor de cadena que representa el mes y el año del campo de mes.

Compatibilidad del navegador

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Compatibilidad 10.0 Compatibilidad Compatibilidad Compatibilidad

Atención:El elemento <input type="month"> no muestra ningún campo de fecha ni calendario en Firefox.