Input Month defaultValue Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Month

Description

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>
<html>
<body>

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

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

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

<script>
function myFunction() {//w ww. jav  a  2s.co  m
    var x = document.getElementById("myMonth");
    x.defaultValue = '1998-11';
}
</script>
</body>
</html>

Related Tutorials