Input Month defaultValue attribute

Definition and usage

defaultValue Sets or returns the default value of the month field.

Note:The default value is HTML value attribute as specified.

The difference between defaultValue and value attributes is that defaultValue contains the default value, while value contains the current value after some changes. If there is no change, defaultValue and value are the same (see "More Examples").

The defaultValue attribute is very useful if you want to check if the month/year of the month field has changed.

Instance

Example 1

Change the default value of the month field:

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

Try it yourself

Example 2

Get the default value of the month field:

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

Try it yourself

Example 3

Here is 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 defaultValue attribute:

monthObject.defaultValue

Set the defaultValue attribute:

monthObject.defaultValue = value

Attribute Value

Value Description
value Specify the default value of the month field.

Technical Details

Return Value: String value, representing the default value of the month field.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support

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