TechGuy
TechGuy

Reputation: 4570

JQuery datepicker pre define dates

I have a JQuery date picker and i wanted to highlight several dates that are pre-define dates.I saw several answers while googling,but not success

My code:

var availableDates = ["30-1-2016", "15-1-2016", "16-1-2016"];

$('#Datepicker').datepicker({
  beforeShowDay: availableDates 
});

But it doesn't show the 'available dates'( Actually i wanted to highlight available dates in the jquery calendar )

Upvotes: 0

Views: 52

Answers (1)

Thangaraja
Thangaraja

Reputation: 956

Please use the below JS

var datesToBeHighlighted=['1/1/2016','1/5/2016'];

$('.datepicker').datepicker({
         inline: true,
         beforeShowDay: function (date) {
            var theday = (date.getMonth()+1) +'/'+ date.getDate()+ '/' + date.getFullYear();
            return [true,$.inArray(theday, datesToBeHighlighted) >=0?"hightlight":''];
                        }
});

JsFiddle : https://jsfiddle.net/Lokcre03/

Upvotes: 4

Related Questions