Dates Available with JQuery UI (array driven)
Dates Available with JQuery UI (array driven)
by Andrew Pougher
HTML
<input type='text' id='txtDate' />
CSS
body{background:#eee}
JavaScript
var availableDates = ["16-1-2015","15-1-2015","14-1-2015"];
// 0 = sun, 1 = Mon, 2 = Tues etc... + those passed from the above array as per "available"
$(function()
{
$('#txtDate').datepicker({ beforeShowDay:
function(dt)
{
return [dt.getDay() == 0 || dt.getDay() == 6 || dt.getDay() == 3|| available(dt), "" ];
}
, changeMonth: true, changeYear: false});
});
function available(date) {
dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
if ($.inArray(dmy, availableDates) != -1) {
return true;
} else {
return false;
}
}