views:

118

answers:

1

I'm using the following script below to add "+1 day" to second field (#returningdate). But if a user chooses on the #leavingdate 12/31/2009 they would get a #returningdate of 12/32/2009 instead of 01/01/2010. This happens with any end month date.

<script type="text/javascript">
  $(function() {
        $("#leavingDate").change(function(){
             $("#returningDate").datepicker( 'setDate' , "+1 day" );

             var date = this.value.split("/");
             $("#returningDate").val(date[0]+'/'+(parseInt(date[1])+1)+'/'+date[2]); 
        }).datepicker();
        $("#returningDate").datepicker();
  });
  </script>
A: 

You can use the built-in javascript Date object to manipulate dates:

  $(function() {
        $("#leavingDate").change(function(){
             $("#returningDate").datepicker( 'setDate' , "+1 day" );

             var date = new Date( Date.parse( this.value ) );
             date.setDate( date.getDate() + 1 );
             $("#returningDate").val(date.getMonth()+'/'date.getDate()+'/'+date.getFullYear()); 
        }).datepicker();
        $("#returningDate").datepicker();
  });
jewel
I tried you're example but I can't seem to get the calendar to launch now. <script type="text/javascript"> $(function() { $("#leavingDate").change(function(){ $("#returningDate").datepicker( 'setDate' , "+1 day" ); var date = new Date( Date.parse( this.value ) ); date.setDate( date.getDate() + 1 ); $("#returningDate").val(date.getMonth()+'/'date.getDate()+'/'+date.getFullYear()); }).datepicker(); $("#returningDate").datepicker(); }); </script>
Swagger
My bad. Your solution works perfectly. Some characters didn't copy over correctly on my end.
Swagger