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 specified in the following.

The difference between defaultValue and value properties 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 property is very useful if you want to check whether 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 properties:

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

Try it yourself

Syntax

Return the defaultValue property:

monthObject.defaultValue

Set the defaultValue property:

monthObject.defaultValue = value

Attribute Value

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

Technical Details

Return Value: A 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.