Hi!
Does anyone know how to add events to this calendar?
Edit fiddle - JSFiddle - Code Playground
/very grateful for help.
Hi!
Does anyone know how to add events to this calendar?
Edit fiddle - JSFiddle - Code Playground
/very grateful for help.
What do you mean? Do you want to insert it from an AJAX call using PHP from a database or just add things in the JS script? Confused on what you are asking for help with…
Events canned like holidays? Events pulled from a database from a database table? More info please…
I mean… what is the best way of doing it?
I would like to do it in the JS script, if it is possible?
I want it to work like this:
You klick on a day and a form show up, this you can save in an db.
If there is an event on a day, the event shows up.
I have done it in php, but this code is so neat so I want to use it.
I know how to save and get things from the db.
The problem is to get the klick on a day to work?
And how to know the date of that day?
/Anette
Well, perhaps you do not understand JS. I will explain.
PHP is SERVER-SIDE. All processing is done on the server only. You never see PHP code in a browser unless it is displayed on purpose. All PHP is processed, then the output of it is sent to the browser. The PHP can communicate with your database system. DB systems are also processed on the server before the browser ever sees anything.
Javascript and JQuery is BROWSER-SIDE only. It does not see the server and does not see the database. It is code that runs in the browser only.
Now that this is explained, there is a way for JS to get to the browser. You can create a PHP file on the server and call it from JS using AJAX. AJAX is a part of JS that lets you call files on the server. Therefore, you could still use the database to save and load dates that way. You would need to save the date in the database and retrieve it. You can not save data using JS directly.
Not sure what you really want to use JS for this type of application. Not sure if this helps or makes it worst for you. I would guess the best way is to create PHP routines to save the dates to the DB and another one to retrieve them back. But, why not just use PHP? Less work to just use a modal display to save them and have the page load them from the DB.
When you say you want to click on a day, what do you want it to do then? If you just want something to happen when you press on a day of the month, you can add JS to the displayed day, loosely like this…
Replace this part:
days += `<div>${i}</div>`;
(Which creates the displayed day number) with something loosely like this:
days += `<div><a href="javascript:void(0);" onclick="myFunction();">${i}</a></div>`;
You can then create a function to handle whatever you need. Not sure, but, guess you could create an alert pop-up or add a modal pop-up for the details of the date…
Thank You so much for this explanation.
The best thing seems to be a combination of JS, PHP and AJAX.
Now I know how to proceed.
Thanks/Anette
Well, there are a million examples on the internet about how to do it.
Here is a site that explains how it works. Basically, you create a PHP file on the server that pulls out the data you need. For example a list of dates from a calendar database table for one month. And, if you have the PHP file respond with the html for the calendar, you can just save that into the calendar’s ID using the AJAX call. (since you said you did it in PHP, you are half way there! ) This site explains it in detail:
JS-Ajax-Tutorial
Good luck!