Dynamic event calendar in javascript

Code Snippet: Calendar pure javascript
File Type: Zip [HTML, CSS, JavaScript]
Author: Adi Jaya
Edit Code online: View on CodePen

Share This:

Published: 5 months ago
Last Updated: 5 months ago
Downloads: 3,827

This JavaScript code example helps you to create a dynamic calendar widget. It renders days, months, and years dynamically into a div element. The calendar widget comes with a user-friendly interface to navigate the next and previous month. Besides this, users can also jump to a specific month or year by selecting through a select dropdown.

You can easily integrate this calendar widget into your website/app project to display a general-purpose calendar. Similarly, you can customize the appearance of the calendar with additional CSS.

Moreover, the calendar widget supports French and Indonesian languages. Basically, this calendar widget displays only dates with navigation. If you want to create a dynamic calendar with daily events, check this calendar widget.

How to Create Dynamic Calendar in JavaScript

1. First of all, create the HTML structure for the basic interface of the calendar as follows:

         

‹ ›
Jump To: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

You can place the above HTML anywhere on your webpage where you want to display the calendar. If you want to change the language, set it through the data-lang attribute. The available languages are as follows:

  • en for English [default]
  • id for Indonesian
  • fr for French

2. After that, style the calendar using the following CSS styles. You can set the custom CSS values in order to change the interface of the calendar according to your theme.

.wrapper {
    margin: 15px auto;
    max-width: 1100px;
}

.container-calendar {
    background: #ffffff;
    padding: 15px;
    max-width: 475px;
    margin: 0 auto;
    overflow: auto;
}

.button-container-calendar button {
    cursor: pointer;
    display: inline-block;
    zoom: 1;
    background: #00a2b7;
    color: #fff;
    border: 1px solid #0aa2b5;
    border-radius: 4px;
    padding: 5px 10px;
}

.table-calendar {
    border-collapse: collapse;
    width: 100%;
}

.table-calendar td, .table-calendar th {
    padding: 5px;
    border: 1px solid #e2e2e2;
    text-align: center;
    vertical-align: top;
}

.date-picker.selected {
    font-weight: bold;
    outline: 1px dashed #00BCD4;
}

.date-picker.selected span {
    border-bottom: 2px solid currentColor;
}

/* sunday */
.date-picker:nth-child[1] {
  color: red;
}

/* friday */
.date-picker:nth-child[6] {
  color: green;
}

#monthAndYear {
    text-align: center;
    margin-top: 0;
}

.button-container-calendar {
    position: relative;
    margin-bottom: 1em;
    overflow: hidden;
    clear: both;
}

#previous {
    float: left;
}

#next {
    float: right;
}

.footer-container-calendar {
    margin-top: 1em;
    border-top: 1px solid #dadada;
    padding: 10px 0;
}

.footer-container-calendar select {
    cursor: pointer;
    display: inline-block;
    zoom: 1;
    background: #ffffff;
    color: #585858;
    border: 1px solid #bfc5c5;
    border-radius: 3px;
    padding: 5px 1em;
}

3. Finally, add the following JavaScript code to functionalize the calendar.

function generate_year_range[start, end] {
    var years = "";
    for [var year = start; year  daysInMonth[month, year]] {
                break;
            } else {
                cell = document.createElement["td"];
                cell.setAttribute["data-date", date];
                cell.setAttribute["data-month", month + 1];
                cell.setAttribute["data-year", year];
                cell.setAttribute["data-month_name", months[month]];
                cell.className = "date-picker";
                cell.innerHTML = "" + date + "";

                if [ date === today.getDate[] && year === today.getFullYear[] && month === today.getMonth[] ] {
                    cell.className = "date-picker selected";
                }
                row.appendChild[cell];
                date++;
            }


        }

        tbl.appendChild[row];
    }

}

function daysInMonth[iMonth, iYear] {
    return 32 - new Date[iYear, iMonth, 32].getDate[];
}

That’s all! hopefully, you have successfully integrated this JavaScript dynamic calendar example into your project. If you have any questions or facing any issues, feel free to comment below.

Related Code Snippets:

How do I create a dynamic event calendar in HTML?

How to use it:.
To use the component, make sure you have jQuery library and Bootstrap 4 framework loaded in the document. ... .
Load the latest moment. ... .
Load the calendar's stylesheet in the document. ... .
Create a DIV container to hold the event calendar. ... .
Import the loading spinner module if needed..

How do you make a working calendar in HTML?

Approach: First we will be using the table tag, which will be used to create the structure of the calendar. This will give us an idea of how the calendar is created using HTML. Later we will apply some CSS property to make the design of the calendar better.

How do I add events to my Evo calendar?

How to use it:.
Add jQuery evo-calendar plugin's JavaScript and CSS files into the HTML document. ... .
Create a container to hold the event calendar. ... .
Create events in an array of objects containing dates, event names and event types [event, holiday, birthday]. ... .
Call the function to generate an event calendar on the page..

Chủ Đề