Reputation: 561
I'm receiving an array from a database with some dates and a description for each day. I wish to display a jquery datepicker calendar where the specified dates are displayed with a custom css class. Besides that the user should be able to click on the specific date and get the description displayed in a different div element.
The first part with the css class is working, but I can't get the description to display. This is what I have so far:
var Event = function(text, className) {
this.text = text;
this.className = className;
};
var events = {};
events[new Date("09/18/2012")] = new Event("description 1", "pink");
events[new Date("09/19/2012")] = new Event("description 2", "green");
$("#minical").datepicker({
beforeShowDay: function(date) {
var event = events[date];
if (event) {
return [true, event.className, event.text];
}
else {
return [true, '', ''];
}
},
onSelect: function(dateText, inst) {
},
minDate: "-3Y",
maxDate: "+3Y",
showButtonPanel: true,
changeMonth: true,
changeYear: true,
altFormat: "yy-mm-dd",
defaultDate: "+1w",
"showButtonPanel": true
});
<style>
.pink > a {
background-color: pink !important;
background-image:none !important;
}
.green > a {
background-color: green !important;
background-image: none !important;
}
</style>
Thx in advance
Upvotes: 0
Views: 844
Reputation: 479
Im not sure if i understand your needs, but if I understand it correct, you want to display the desciption of the selected date/event in another div.
your onSelect
event could be like this:
onSelect: function(dateText, inst) {
var event = events[new Date(dateText)];
$("#description").html(event.text);
}
Upvotes: 1