Reputation: 1427
I am try to load the date range current year and previous year(2017,2018) based on selected dropdown. But my date picker is showing only which years first selected.
I can show the years which is first selected. Example First selected year- 2017 means show the 2017 calender Second change selected year- 2018 means show the 2017 calender
HTML Code:
<?php $year = date('Y'); ?>
<select name="hyear" id="hyear" data-placeholder="Select Year" class="form-control chosen-select">
<option value="<?php echo $year ?>"><?php echo $year ?></option>
<option value="<?php echo ++$year ?>"><?php echo $year ?></option>
</select>
Script code:
function updateDatePic(mindate, maxdate)
{
$('#hdate').datepick({
minDate: mindate,
maxDate: maxdate,
onSelect: function () {
}
});
}
$('#hyear').change(function () {
var year = $.trim($("#hyear").val());
var mindate = '01/01/' + year;
var maxdate = '12/31/' + year;
alert("mindate="+mindate+"...maxdate="+maxdate);
updateDatePic(mindate, maxdate);
});
Please advise!
Upvotes: 3
Views: 78
Reputation: 616
Kindly use this code:
$( "#hdate" ).datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: '2017:2018'
});
Upvotes: 2