I previously asked question to set one date picker dates with respect to month/year change of another date picker. I didn't get exact answer, but somehow I managed to get min and max dates to set to a date picker by referring various stack overflow answers. But that min and max date settings are not working properly.
Month and year picking date picker:
<label> Month</label>
<div class="input-group date">
<input type="text" class="form-control pull-right" id="txtMonth" onchange="MonthDatePick();">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
</div>
My selected month date picking datepicker:
<div class="col-lg-3">
<label> From</label>
<div class="input-group date">
<input type="text" class="form-control pull-right" id="txtFrom">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
</div>
</div>
Script:
function MonthDatePick() {
var month = $('#txtMonth').datepicker('getDate').getMonth() + 1;//('getMonth');
var year = $('#txtMonth').datepicker('getDate').getFullYear();//('getFullYear');
var minDate = new Date(year, month-1, 1);
var maxDate = new Date(year,month, 0);
$("#txtFrom").datepicker({
autoclose: true,
minDate: minDate,
maxDate: maxDate,
format: 'dd/mm/yyyy',
//defaultDate:minDate,
changeMonth: false,
changeYear: false,
});
}
I debugged and found out that when I select month, min and max dates were defined.
For Ex: If I choose, Feb 2018
means,
min date comes as :01/02/2018
max date comes as : 28/02/2018,
but the change does not replicate in my date selecting date picker
Debugging image picture
Debugging image picture showing min date
Here is my fiddle
How to fix this?