Toni Michel Caubet
Toni Michel Caubet

Reputation: 20173

jquery datepicker dependent end date

I need to select a date range, with to inputs. To do so I am using two inputs with the jquery datepicker plugin,

Actually, I'm trying with the code in their site, I just changed the dateformat param, because I need it like this as I'm extending some framework:

jQuery(function (e) {
    jQuery('.start_date').datepicker({ 
        minDate: 2,
        dateFormat: 'mm/dd/yy',
         onClose: function( selectedDate ) {

            jQuery( ".end_date" ).datepicker( "option", 
                                              "minDate", 
                                              selectedDate 
            );
        }
    });
    jQuery('.end_date').datepicker({ 
        minDate: 2,
        dateFormat: 'mm/dd/yy'                              });
});

Wich works great,

Its selecets (or redeclare) the end_date acording to the start_date.

But how can I do that the end_date is next day?

I mean, if start_date is 01/01/2013 I need the first possible value for end_date to be 01/02/2013

how can I do so?

-EDIT-

Basically, how can I increase selectedDate in one day?

Upvotes: 1

Views: 2610

Answers (1)

Malk
Malk

Reputation: 11983

var dates = jQuery('.start_date, .end_date').datepicker("option", "onSelect", 
   function(selectedDate){
       var $this = $(this),
           option = $this.hasClass("start_date") ? "minDate" : "maxDate",
           adjust = $this.hasClass("start_date") ? 1 : -1,
           base_date = new Date(selectedDate),
           new_date = new Date();

       new_date.setDate(base_date.getDate() + (1 * adjust));
       dates.not(this).datepicker("option", option, new_date);

   }
);

Fiddle: http://jsfiddle.net/HXmVe/

Upvotes: 3

Related Questions