Is there a way to automatically get the date when the year and month are selected without clicking the done button?
$(function() {
$('.date-picker, .to').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'yy-mm-dd',
onClose: function(dateText, inst) {
$(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
$('#to').datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth + 1, 0));
}
});
});
.ui-datepicker-calendar {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" integrity="sha512-uto9mlQzrs59VwILcLiRYeLKPPbS/bT71da/OEBYEwcdNUk8jYIy+D176RYoop1Da+f9mvkYrmj5MCLZWEtQuA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<label for="startDate">Year/Month :</label>
<input name="startDate" id="startDate" class="date-picker" />
<input name="startDate" id="to" class="to" />
jquery
script since you are using the jQuery selector$
, and thejquery-ui
script since you are usingdatepicker
, a jQuery UI widget. CDNs for those scripts can be found here at cdnjs.comonChangeMonthYear
event? Reading the documentation is a good habit to get into.