I've looked at a few question on here and online but i cant seem to find the answer im looking for or maybe i just cant implement it right. I have 2 datepickers...a check in date and a check out date. The check out date must always be within 30 days of the check in date. I've managed to use the code below to get this result however its on an onSelect therefore it dosent work when the page is loaded, only when u select a check in date. By default the check in date is today therefore the check out should only be selectable for up to 30 days from when the page loads. Any help would be appreciated.
var today = new Date();
today.setHours(0,0,0,0);
$(function(){$( "#datepicker, #departure" ).datepicker({
defaultDate: +1,
minDate: 0,
maxDate: '+12m',
dateFormat: 'dd/mm/yy',
numberOfMonths: 3,
showOn: 'both',
buttonImageOnly: true,
buttonImage: 'http://images.aboutrooms.com/hotels/graphics/calendar.gif',
//beforeShowDay: function(date){return [date.getTime() != today.getTime(), ''];}
onSelect: function( selectedDate ) {
if(this.id == 'datepicker'){
var dateMin = $('#datepicker').datepicker("getDate");
var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(),dateMin.getDate() + 1); // Min Date = Selected + 1d
var rMax = new Date(dateMin.getFullYear(), dateMin.getMonth(),dateMin.getDate() + 31); // Max Date = Selected + 31d
$('#departure').datepicker("option","minDate",rMin);
$('#departure').datepicker("option","maxDate",rMax);
}
}
});
});