Boy Pasmo
Boy Pasmo

Reputation: 8511

how to set EndDate's minDate to what value is in StartDate

Say you have two datepicker.

$("#StartDate").datepicker({
  mindDate: 0
});

$("#EndDate").datepicker({
  minDate: // how to set here the StartDate's value?
});

How can I set the minDate of $("#EndDate") to whatever value is in $("#StartDate")?

What I have tried so far is,

$("#EndDate").datepicker({
  beforeShow: function() {
    $(this).datepicker('minDate', $("#StartDate").val(); // Still not getting the value from #StartDate
  }
});

Still the minDate is not taking into effect. What should I do to make it right? Any thought? Thanks

Upvotes: 0

Views: 639

Answers (1)

Nicolas R
Nicolas R

Reputation: 14619

Use the sample provided by jQuery! With OnClose :

$(function() {
    $("#StartDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 3,
        onClose: function( selectedDate ) {
            $("#EndDate").datepicker( "option", "minDate", selectedDate );
        }
    });

    $("#EndDate").datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 3,
        onClose: function( selectedDate ) {
            $("#StartDate").datepicker("option", "maxDate", selectedDate);
        }
    });
});

See here: http://jqueryui.com/datepicker/#date-range

Upvotes: 1

Related Questions