Elaborating Rob Van Dam's answer, here is a code sample (using jQuery UI datepicker) for fetching enabled dates using AJAX. I use AJAX to query a PHP page that returns the enabled date from a database (because I only want to show dates where I have actual data).
The idea is to do the AJAX query each time the user change month and then store the enabled dates for this month in a global array (allowedDates) that is later used by beforeShowDay.
Of course, you could do the AJAX query in beforeShowDay, but this would be quite inneficient due to the high number of AJAX queries (more than 30 for each month).
var allowedDates = new Object();
function queryAllowedDates (year, month, id) {
$.ajax({
type: 'GET',
url: 'calendar_days.php',
dataType: 'json',
success: function(response) {
allowedDates[id] = response.allowedDates;
},
data: {year:year,month:month},
async: false
});
}
$("#datepicker1").datepicker({
dateFormat: 'dd.mm.yy',
changeMonth: true,
changeYear: true ,
beforeShow: function (input) {
var currentDate = $(input).datepicker('getDate');
var id = $(input).attr('id');
queryAllowedDates(currentDate.getFullYear(), currentDate.getMonth()+1,id);
},
onChangeMonthYear: function (year, month, inst) {
queryAllowedDates(year, month, inst.input.attr('id'));
},
beforeShowDay: function (day) {
var id = $(this).attr('id');
var date_str = [
day.getFullYear(),
day.getMonth() + 1,
day.getDate()
].join('-');
if (allowedDates[id] != undefined && allowedDates[id][date_str]) {
return [true, 'good_date', 'This date is selectable'];
} else {
return [false, 'bad_date', 'This date is NOT selectable'];
}
}
});
In this example, the PHP page returns a JSON array containing something like :
{"allowedDates":{"2008-12-04":1,"2008-12-11":1}}