Input Month value Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Month

Description

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

The value attribute sets a month and year for the month field.

Set the value property with the following Values

Value Description
YYYY-MM Sets the month and year.
  • YYYY - year (e.g. 2011)
  • MM - month (e.g. 01 for January)

Return Value

A String, representing the month and year of the month field

The following code shows how to Set the month and year for 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 onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*from   w w w . j av a  2  s  .  co m*/
    document.getElementById("myMonth").value = '2997-11';
    document.getElementById("demo").innerHTML = 'set';
}
</script>
</body>
</html>

Related Tutorials