I would suggest using jQuery's datepicker to do date-range constraining on the client side. You would need to disable the input elements <input readonly/>
. I've implemented a date range constraint recently that works for me. It constrains an end-date to be within 90 days of the start-date
FYI, I stopped using startElement and endElement as a test, never went back as this code isn't currently reused.
// ============================================================================
// FUNCTION: InitializeDates(startElement, endElement)
// PARAMETERS
// ----------
// startElement: The element which will be initialized as the start-date
// datepicker.
//
// endElement: The element which will be initialized as the start-date
// datepicker.
//
// DESCRIPTION
// -----------
// InitializeDates updates the start and end dates for non-employees. It
// creates a date-picker object on both fields and then constrains the end
// end date:
// * No date selections available prior to the start date
// * No date selections available after 90 days beyond the start date.
// ----------------------------------------------------------------------------
function InitializeDates(startElement, endElement)
{
$("#f-start-date").datepicker({
showOn: "button",
buttonImage: "images/calendar.png",
buttonImageOnly: true,
onSelect: function(dateText, inst) { StartDateSelected(dateText, inst) }
});
$("#f-end-date").datepicker({
showOn: "button",
buttonImage: "images/calendar.png",
buttonImageOnly: true,
numberOfMonths: 3
});
$("#f-start-date").val('');
$("#f-end-date").val('');
}
// ============================================================================
// FUNCTION: StartDateSelected(dateText, endElement)
// PARAMETERS
// ----------
// dateText: The dateText passed from jQuery.datepicker.onSelect
// inst: The instpassed from jQuery.datepicker.onSelect//
//
// DESCRIPTION
// -----------
// Updates the end-date maxDate and minDate fields to 91 dates from the selected
// start date.
// ---------------------------------------------------------------------------
function StartDateSelected(dateText, inst)
{
var second = 1000;
var minute =second * 60;
var hour = minute * 60;
var day = hour * 24;
// The datepicker updates maxDate and minDate based on today's date. I've
// got to math out dates so that the maxDate is actually 91 days from the
// selected date.
var todaysDate = new Date();
var selectedDate = new Date(dateText);
var duration = Math.floor((selectedDate - todaysDate) / day) + 91;
$("#f-end-date").datepicker("option", "minDate", selectedDate);
$("#f-end-date").datepicker("option", "maxDate", duration);
$("#f-end-date").val('');
}