Change the default value of a month field:
document.getElementById("myMonth").defaultValue = "2020-02";
Click the button to change the default value of the month field.
<!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() {// w w w. java2s. c o m document.getElementById("myMonth").defaultValue = "2020-02"; } </script> </body> </html>
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.
The 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.
The <input type="month"> element is not supported in Firefox.