This code used to work but now it doesn’t and it’s only taking the first value in the array…
var unavailableDates is an array that stops dates showing on the datepicker..
any ideas??
It’s not cycling through all dates in the array for some reason!?!?
var unavailableDates = ["4-7-2011","5-7-2011"];
function unavailable(date) {
var dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
if ($.inArray(dmy, unavailableDates) == 0) {
return [false, "", "Unavailable"];
} else {
var day = date.getDay();
return [(day != 0 && day != 2 && day != 3 && day != 4 && day != 6)];
}
}
$(function(){
$('#smh').datepicker({
showOn: "both",
buttonImage: "images/calendar.gif",
buttonImageOnly: true,
beforeShowDay: unavailable,
minDate: -0,
dateFormat: "dd/mm/yy",
onSelect: function(e) {
e = e.split('/')[1] + '/' + e.split('/')[0] + '/' + e.split('/')[2];
var date = new Date(e);
var day = date.getDay(); // 0 = sunday etc...
if (day === 1) {
$("#check2").hide();
$("#text").hide();
$("#check1").show();
} else if (day === 5) {
$("#check1").hide();
$("#text").hide();
$("#check2").show();
}
$("#bdate").html(this.value);
}
})
In jQuery the
$.inArray(elem, array)method returns -1, and not 0, whenelemis not found inarray.So I think you should use:
if ($.inArray(dmy, unavailableDates) == -1)
instead of:
if ($.inArray(dmy, unavailableDates) == 0)