jQuery Datepicker: How to Mark the Holidays on Calendar

Jquery UI has a fully-featured and highly customizable date picker control that let us create and customize the control based on our requirements.

To create a basic date control, you just need to call the below single line of code

input field:

The Date Picker will appears when textbox has the focus, and user can select the date. It disappears when loses focus or date selected. This component is fully localizable, can display multiple months at once, handles any date format, has date range restriction, and more. It has lot options and events available you to tweak.

Here, i would like to create a date control that will mark the holidays on the calendar.
See live Demo here and view the source if you’d like.

Mark Holidays in Date Picker

First, we need to create the holiday array list:

If you need to populate the holidays from database, create the array at server side and inject that into client side.

Above code, i have used “beforeShowDay” event, it takes a date as a parameter and must return an array with [0] equal to true/false indicating whether or not this date is selectable, [1] equal to a CSS class name(s) or ” for the default presentation, and [2] an optional popup tooltip for this date. It is called for each day in the datepicker before it is displayed.

Here, “setHoliDays” function returns the array with 3 values, [0] as ‘true’ (you can change this to ‘false’ if you want to disable holiday date), [1] is css class name as “holiday” (style the holiday using this css selector), and [1] is name of the holiday to be showed as a tooltip (it will show when you hover on the date)

You have to include the below style inside the head tag to display the holidays with different background color

Comments

  1. By riggs

    Reply

  2. Reply

  3. By derwahrealex

    Reply

    • By admin

      Reply

  4. By Jacky

    Reply

    • By admin

      Reply

  5. By raj

    Reply

  6. By Prachi

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Bitnami