views:

10

answers:

1

I have two datepickers:

$('#Date1, #Date2').datepicker({
  defaultDate: +1,
  minDate: +1
});

Whenever I select a date in Date1, I want to set this picked date as the minDate in Date2. I setted a function call for the onclick of Date1.

function RefreshDate2() {
  $("#Date2").datepicker({
    defaultDate: $("#Date1").datepicker("getDate"),
    minDate: $("#Date1").datepicker("getDate")
  });
  $("#Date2").datepicker("refresh");
}

The function runs but it doesn't work, the minDate of Date2 still is the today+1 (as configured in the first sentence). Any ideas on how to fix it?

Thanks in advance!

+1  A: 

You're trying to re-create the picker, instead set its options using the
.datepicker('option', options) method, like this:

function RefreshDate2() {  
  var d1 = $("#Date1").datepicker("getDate");
  $("#Date2").datepicker('option', {
    defaultDate: d1,  
    minDate: d1
  }).datepicker("refresh");  
}
Nick Craver
It works! Thanks!
scardazzi