document.addEventListener('DOMContentLoaded', function () { var calendarEl = document.getElementById('calendar'); let date = new Date();//original date let firstDay = new Date(); firstDay.setDate(date.getDate() + 1); //Set firstDay to the day after date firstDay = firstDay.toJSON().slice(0, 10); //Converts firstDay to a string in the format 'yyyy-mm-dd' let yearBehind = new Date(); yearBehind.setYear(date.getYear() - 1); yearBehind = yearBehind.toJSON().slice(0, 10); let yearAhead = new Date(); yearAhead.setYear(date.getYear() + 1); yearAhead = yearAhead.toJSON().slice(0, 10); let randomDay = new Date(); randomDay.setDate(date.getDate() + 4); date = date.toJSON().slice(0, 10); var calendar = new FullCalendar.Calendar(calendarEl, { headerToolbar: { left: 'today next', center: 'title', right: 'dayGridMonth' }, initialDate: firstDay, selectable: true, selectMirror: true, select: function (arg) { var start = arg.start;// the date the user selected var end = arg.end; var nextDay = new Date(start); nextDay.setDate(start.getDate() + 1); // add one day to start if (nextDay.toISOString().slice(0, 10) != end.toISOString().slice(0, 10)) { calendar.unselect();//forces you to only select one day } else { var userResponse = confirm("Are you sure you want to book this day?"); if (userResponse) { $.ajax({ url: '/Controller/StoreDate/SaveDate', type: 'POST', // HTTP method, use POST to send data data: { 'data': start }, // Data sent to server success: function (response) { // This function runs if the request succeeds console.log(response); }, error: function (error) { // This function runs if the request fails console.log(error); } }); window.location.href = "/Home/Index";//sends you to another page when you're done } } }, events: [ { groupId: 'available', start: firstDay, end: yearAhead, display: 'background' }, { start: firstDay,//offer days end: randomDay, display: 'background', color: 'dimgrey' }, { groupId: 'unavailable', start: yearBehind,//unavailable days end: date, display: 'background', color: '#ff9f89' } ] }); calendar.render(); });