0

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?

2
  • 3
    declare var input = []; outside the function otherwise it will override the existing value Commented Oct 16, 2015 at 13:44
  • 1
    you are defining the array inside of your function, therfor it is always generated again. You need to make the var input =[] outside of your function. Commented Oct 16, 2015 at 13:44

1 Answer 1

4

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');
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.