Input Month defaultValue Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Month


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

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

You can use defaultValue property to find out whether the month/year of a month field have been changed.

Set the defaultValue property with the following Values

Value Description
value Sets the default value of the month field

Return Value

A String, representing the default value of the month field

The following code shows how to change the default value of a month field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

Month and year: <input type="month" id="myMonth" value="1997-11">

<button type="button" onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {//w ww. jav  a  m
    var x = document.getElementById("myMonth");
    x.defaultValue = '1998-11';

Related Tutorials