Set the month and year for a month field:
document.getElementById("myMonth").value = "2020-02";
Click the button to set a month and year for the month field.
<!DOCTYPE html> <html> <body> Month and year: <input type="month" id="myMonth"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w ww . ja va 2 s . c om*/ document.getElementById("myMonth").value = "2020-02"; } </script> </body> </html>
The value property sets or gets the value attribute of a month field.
The value attribute specifies a month and year for the month field.
The <input type="month"> element is not supported in Firefox.
Value | Description |
---|---|
YYYY-MM | Specifies the month and year. YYYY - year (e.g. 2020) MM - month (e.g. 01 for January) |
The value property return a String representing the month and year of the month field.