Subho
Subho

Reputation: 923

How to add elements to a JavaScript array on each click

I am using the FullCalendar API which shows the user a calendar. When the user clicks each date, the date pops up. I want to add the date in a JavaScript array on each click. As I have my code now, the date is being updated but not added to my array.

Here is what I have done:

select : function(date, jsEvent, view) {
        $('#clickedDateHolder').val(date.format());
        // show modal dialog
        var input = [];
        input.push(date.format());
        $('#selectedDate').val(input);
        $('#event-modal').modal('show');
    }

How can I update my code in order to generate an array of all of the dates the user has clicked?

Upvotes: 0

Views: 98

Answers (1)

tymeJV
tymeJV

Reputation: 104775

You'd have to declare the array of dates outside the select handler, ex:

var selectedDates = [];
$(el).fullCalendar({
    select : function(date, jsEvent, view) {
        $('#clickedDateHolder').val(date.format());
        // show modal dialog
    //var input = [];
        selectedDates.push(date.format());
        $('#selectedDate').val(input);
        $('#event-modal').modal('show');
    }
});

Upvotes: 4

Related Questions