I have 2 input boxes; one for the start date and the other for the end date. What I need is that when user selects the first date, the second date should automatically switch to the month of the first date. I am using the following script; and whenever I choose a date from the past, the second box pops up with today’s date.
Any ideas?
Thanks
$(function() {
var dates = $( "#from, #to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
changeYear: true,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
One way of solving the problem might be to change the second value together with the first value whenever the first value is changed by user. This can be accomplished by adding few lines at the end of onSelect function.
Working example http://jsfiddle.net/5gbpA/