Datepicker: How do I set a maximum range of dates between two input fields?
I have two input fields (startDate and endDate) on a hotel reservation
form. The restrictions that must be observed are that 1. startDate not
be greater than endDate, 2. endDate not be less than startDate, and 3.
the difference between startDate and endDate not be greater than 6
weeks. I found some sample code on the jQuery website that addresses 1
and 2, but I'm having trouble setting the maximum allowed range
between startDate and endDate. Here's what I have so far:
<pre>
$(document).ready(function() {
$("#startDate,#endDate").datepicker({
dateFormat: "MM d, yy",
showStatus: true,
beforeShow: customRange,
numberOfMonths: 2,
buttonImage: "../images/calendar.png",
}).addClass("embed").attr("readonly", "readonly");
function customRange(input) {
return {
minDate: (input.id == "endDate" ? $
("#startDate").datepicker("getDate") : 1),
maxDate: (input.id == "startDate" ? $
("#endDate").datepicker("getDate") : 365)};
}
</pre>