set and show the date of a second datepicker according to the setting of a first datepicker

set and show the date of a second datepicker according to the setting of a first datepicker

 Hello,

 

i have two datepicker:

  - first datepicker for the start date

  - second datepicker for the end date

code - first datepicker :

   $('#datepicker').datepicker({ 
         minDate : 0,
         maxDate : '+31D',
         firstDay : 0,
          dateFormat: 'yy-mm-dd', 
          buttonImage: '../images/datepicker/calendar.gif',  
          showOn: 'both', 
          onSelect: function(date) { 
            var day = $("#datepicker").datepicker("getDate");
            day.setDate(day.getDate());
            $("#datepicker2").datepicker("option","minDate",day); 
      }         
       }); 











code - second datepicker :

        $('#datepicker2').datepicker({      
         minDate : 0,
         maxDate : '+31D',
         firstDay : 0,
          dateFormat: 'yy-mm-dd', 
          buttonImage: '../images/datepicker/calendar.gif',  
          showOn: 'both'        
       }); 






....

i have also two input :

<input name="datepicker" id="datepicker" type="text" value="<?=$date_start?>"  >

and

<input name="datepicker2" id="datepicker2" type="text" value="<?=$date_end?>"  >

With this code the second datepicker (datepicker2) has a minDate always set by the first datepicker.

Each time, i select a date in the first datepicker then the minDate of datepicker2 is changed and i can't choose a date previous to the date selected in the first datepicker. This is what i want..

My problem is that i would also like that the first datepicker change the value showed by the second input field when it sets the minDate of the second datepicker.

This way if the second input field (datepicker2 <-> $date_end ) has a value (ex.: 2010-01-17) and the user change his mind and select (first datepicker) a new value for $date_start (ex.: 2010-01-21) then i would like that the input field ($date_end) has a value showed equal to minDate.

Is there a way to do this with ui datepicker?

Thanks,