Reputation: 427
I am trying to add an event in FullCalendar.io through a function javascript.
I have tried in two ways.
Recalling to end page a function or with a click.
I don't receive error but in my calendar the event is not added.
<div id='calendar'></div>
<script language="javascript">
id='13-17-1'
title='TextOK'
start= '2016-04-07T08:30:00'
end= '2016-04-07T09:30:00'
test=addCalanderEvent(id, start, end, title)
function addCalanderEvent(id, start, end, title)
{
var eventObject = {
title: title,
start: start,
end: end,
id: id
};
$('#calendar').fullCalendar('renderEvent', eventObject, true);
alert("OKOK")
}
</script>
<input type="button" onClick="addCalanderEvent('13-17-1','TITLE','2014-09-19T10:30:00','2016-04-19T10:30:00')">
Upvotes: 1
Views: 5231
Reputation: 3265
Here is a sample based off your code to add an event on button click
https://jsfiddle.net/Lra2535n/
/* fullcalendar 2.6.1, moment.js 2.12.0, jQuery 2.2.1, on DOM ready */
$('#calendar').fullCalendar({});
$('#addEvent').on('click', function() {
// Random event id for demo...
var id = Math.random().toString(26).substring(2, 7);
addCalendarEvent(id, '2016-04-08', '2016-04-11', 'An added event ' + id);
});
function addCalendarEvent(id, start, end, title) {
var eventObject = {
id: id,
start: start,
end: end,
title: title
};
$('#calendar').fullCalendar('renderEvent', eventObject, true);
}
Upvotes: 3