THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Input Month value Property

Input Month Object Reference Input Month Object

Example

Change the default value of a month field:

document.getElementById("myMonth").defaultValue = "2014-02";
Try it yourself »

Definition and Usage

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

Note: The default value is the value specified in the HTML value attribute.

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

The defaultValue property is useful when you want to find out whether the month/year of a month field have been changed.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The defaultValue property is supported in all major browsers.

Note: The <input type="month"> element is not supported in Internet Explorer or Firefox.


Syntax

Return the defaultValue property:

monthObject.defaultValue

Set the defaultValue property:

monthObject.defaultValue=value

Property Values

Value Description
value Specifies the default value of the month field

Technical Details

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

More Examples

Example

Get the default value of a month field:

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

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 »

Input Month Object Reference Input Month Object