Set multiple dates in jquery datepicker programmatically

I want to set multiple dates programmatically on an inline jQuery datepicker. I have an array of dates and I want to loop through them and on each iteration, the date must be selected in the datepicker.

The result should be multiple dates selected on an inline jQuery datepicker.

This is what I'm trying, but I haven't had much success.

for(var j=0; j<dateArr.length; j++){
    $("#inlineDp").datepicker.('setDate',dateArr.pop());
}

      

+3


source to share


1 answer


This second part is not a method: it is the constructor part of the datepicker .

What you need to do is loop through your array and use this constructor every time (but initialize the datepicker before the loop).

As for selecting multiple dates, you cannot do this by default (only one date can be selected at a time), so you will need to use a third party plugin .



$("#inlineDp").datepicker();

for (var j = 0; j < dateArr.length; j++) {
    window.setTimeout(function(){
       $("#inlineDp").datepicker("setDate", dateArr[j]);
    }, 500);
}

      

(Note that for the sake of simplicity, this code does not address the issue of timeouts in loops (namely, that they do not work). The code in the demo is below (so you should use the code there instead from the explanatory example above).

Demo

+1


source







All Articles