'How to force a second HTML date input field to open with the same month as the 1st input

With the HTML input type="date" the pop-up calendar always seems to open with today's date. Is there a simple way with vanilla JavaScript to force the pop up calendar to display a different initial month?

In particular we are building a search function for our website, allowing people to search for events between two dates. Once they have selected their starting date for the search, we want the 2nd date input to pop open displaying the month of their first input. Rather than forcing them to page through from today until 2022 or whenever.

We tried simply getting the value of the first input and applying it to the 2nd, but rejected that idea because every time the first input gets altered, the visitor has to reset the second one. Plus we really don't want a date to appear there until the visitor has chosen one.

Don't really want to use a datepicker script, as most of them are bigger than our entire JS load for this website.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source