Select last day of the month for a specific date
by Génesis García Morilla
HTML
<div>
<label>In <input type="date"></label>
<label>Out <input type="date"></label>
</div>
CSS
div {
display: flex;
justify-content: space-around;
}
JavaScript
const $origin_day = document.querySelector('label:first-of-type > input')
const $last_day = document.querySelector('label:last-of-type > input')
$origin_day.onchange = () => {
if (!$origin_day.value) return;
const date = new Date($origin_day.value)
$last_day.value = new Date(date.getFullYear(), date.getMonth() + 1, 1)
.toISOString().slice(0, 10)
}