0

I have two jQuery calendars that are shown all the time on screen. I want the maxDate of the first calendar to be the date of the second, and the minDate of the second to be the date of the first.

I can currently see no way of modifying minDate and maxDate on the fly (i.e. through the onSelect property). How can I get the effect I want?

Pseudo code:

$("#date1").datepicker({
    onSelect: function(selectedDate) {
        //Set minDate property on #date2 to selectedDate
    }
});

$("#date2").datepicker({
    onSelect: function(selectedDate) {
        //Set maxDate property  on #date1 to selectedDate
    }
});

2 Answers 2

1

As described in the documentation you need to:

// setter
$( ".selector" ).datepicker( "option", "minDate", new Date(2007, 1 - 1, 1) );

So

$("#date2").datepicker({
    onSelect: function(selectedDate) {
         $( "#date1" ).datepicker( "option", "maxDate", selectedDate);
    }
});
Sign up to request clarification or add additional context in comments.

Comments

1

You can set the minDate and maxDate programmatically like this:

$("#date2").datepicker({
    onSelect: function(selectedDate) {
        $("#date1").datepicker("option", "maxDate", new Date(selectedDate));
    }
});

Here is the documentation for min/maxDate.

3 Comments

Won't that recreate the original datepicker on "#date1"?
the docs say 'Get or set the minDate option, after initialization:' use my post method :)
@Chris, sorry I copied the wrong statement from the docs, see my update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.