I don’t really get how to code my two datepickers. When I select a certain date with the first datepicker, I want the second one to automatically select a date X days after. The following code is what I have now. What’s left to do?
$(function() {
$.datepicker.setDefaults({
dateFormat: 'yy-mm-dd',
firstDay: 1,
showOn: "both",
buttonImage: "/images/calendar.gif",
buttonImageOnly: true});
$('#txtStartDate').datepicker({minDate: 0, onSelect: function(selectedDate) {
var minDate = $(this).datepicker('getDate');
if (minDate) {
minDate.setDate(minDate.getDate() + 1);
}
$('#txtEndDate').datepicker('option', 'minDate', minDate || 1); // Date + 1 or tomorrow by default
}});
$('#txtEndDate').datepicker({minDate: 1, onSelect: function(selectedDate) {
var maxDate = $(this).datepicker('getDate');
if (maxDate) {
maxDate.setDate(maxDate.getDate() - 1);
}
$('#txtStartDate').datepicker('option', 'maxDate', maxDate); // Date - 1
}});
});
This should help, cheers!
Link: jQuery datepicker- 2 inputs/textboxes and restricting range
Working Demo : http://jsbin.com/evudo but you can find out more options in the link above.
link : http://forum.jquery.com/topic/2-datepickers-start-end-date-get-and-post