THE WORLD'S LARGEST WEB DEVELOPER SITE

Input Month value Property

❮ Input Month Object

Example

Set the month and year for a month field:

document.getElementById("myMonth").value = "2014-02";
Try it Yourself »

Definition and Usage

The value property sets or returns the value of the value attribute of a month field.

The value attribute specifies a month and year for the month field.


Browser Support

Property
value Yes 10.0 Yes Yes Yes

Note: The <input type="month"> element does not show any date field/calendar in Firefox.


Syntax

Return the value property:

monthObject.value

Set the value property:

monthObject.value = YYYY -MM

Property Values

Value Description
YYYY-MM Specifies the month and year. Explanation of components:
  • YYYY - year (e.g. 2011)
  • MM - month (e.g. 01 for January)


Technical Details

Return Value: A String, representing the month and year of the month field

More Examples

Example

Get the month and year of a month field:

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

The result of x will be:

1997-11
Try it Yourself »

Example

An example that shows the difference between the defaultValue and value property:

var x = document.getElementById("myMonth");
var defaultVal = x.defaultValue;
var currentVal = x.value;
Try it Yourself »

Related Pages

HTML reference: HTML <input> value attribute


❮ Input Month Object