Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get selected date from fullcalendar

I added the calendar to my asp.net mvc 2 application from here .

I want to pick the selected date where I am going to enter the event. How can I get selected date?

Also I want to save this date and corresponding event to the database. How to do this also ?

like image 413
Red Swan Avatar asked Oct 18 '10 12:10

Red Swan


2 Answers

Use this code when you setup the plugin

$('#calendar').fullCalendar({
    selectable: true,
    select: function(start, end, jsEvent, view) {
         // start contains the date you have selected
         // end contains the end date. 
         // Caution: the end date is exclusive (new since v2).
         var allDay = !start.hasTime() && !end.hasTime();
         alert(["Event Start date: " + moment(start).format(),
                "Event End date: " + moment(end).format(),
                "AllDay: " + allDay].join("\n"));
    }
});
<link href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.1/fullcalendar.min.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.1/fullcalendar.print.css" rel="stylesheet" media="print"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.1/fullcalendar.min.js"></script>
<div id="calendar"></div>

Please note that I have just included the options needed to answer your question.

For further information refer to the very good made plugin documentation.

like image 132
Lorenzo Avatar answered Oct 14 '22 03:10

Lorenzo


$('#calendar').fullCalendar({
    dayClick: function(date, jsEvent, view) {

        alert('Clicked on: ' + date.format());

        alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);

        alert('Current view: ' + view.name);

        // change the day's background color just for fun
        $(this).css('background-color', 'red');

    }
});
like image 43
Ram K Avatar answered Oct 14 '22 04:10

Ram K