Automatically Open Second Datepicker After First Datepicker Date is Selected

Use setTimeout to set focus to a second datepicker and open it automatically after a date from the first datepicker was selected. Without using setTimeout, the calendar will open and immediately close when focus is set to the second datepicker.

by bmarsh123

HTML

<input name="fromDateCalendar" type="text" value="10/12/2013" id="fromDateCalendar" style="width:100px;" />     

 <input name="toDateCalendar" type="text" value="09/01/2014" id="toDateCalendar" style="width:100px;" />

JavaScript

$(function () {
    $('#fromDateCalendar').datepicker({
        onSelect: function (date) {
            $('#toDateCalendar').datepicker('option', 'minDate', date);
            setTimeout(function() { $('#toDateCalendar').focus(); }, 0);
        }
    });
    
    $("#toDateCalendar").datepicker({
        onSelect: function (date) {
            $('#fromDateCalendar').datepicker('option', 'maxDate', date);
            setTimeout(function() { $('#fromDateCalendar').focus(); }, 0);
        }
    });
});