Reputation: 366
I have a jQuery UI DatePicker calendar that alerts
when a date is clicked that has an event. http://jsfiddle.net/helpinspireme/DuwZL/ What I would like to add is on load, if there is an event on today's date I would like the alert to display when the calendar is loaded. Any help would be greatly appreciated. Thank you.
var events = [
{ Title: "Meeting with boss", Date: new Date("04/13/2012") },
{ Title: "Meeting with manager", Date: new Date("04/13/2012") },
{ Title: "Five K for charity", Date: new Date("04/17/2012") },
{ Title: "Dinner", Date: new Date("04/25/2012") }
];
$("div").datepicker({
beforeShowDay: function(date) {
var result = [true, '', null];
var matching = $.grep(events, function(event) {
return event.Date.valueOf() === date.valueOf();
});
if (matching.length) {
result = [true, 'highlight', null];
}
return result;
},
onSelect: function(dateText) {
var date,
selectedDate = new Date(dateText),
i = 0,
event = null;
while (i < events.length) {
date = events[i].Date;
if (selectedDate.valueOf() === date.valueOf()) {
event = events[i];
alert(event.Title);
}
i++;
}
}
});
Upvotes: 0
Views: 2258