Jquery Date Picker with different links

Go To StackoverFlow.com

0

I am new to Jquery. I am using JQuery DatePicker as a calender entry with some date showing in different colour but my problem is that when I want to assign a link to that date it is now working well...Here is the code

I defined the pink and green as style as well and is working perfect.

var events = {};
    events[new Date("02/14/2011")] = new Event("Valentines Day", "pink");
    events[new Date("02/18/2011")] = new Event("Payday", "green");

    $('#calender').datepicker({
        changeMonth : true,
        changeYear : true,
        beforeShowDay : function(date) {
            var event = events[date];
            if (event) {
                return [ true, event.className, event.text ];
            } else {
                return [ true, '', '' ];
            }
        },
        onSelect : function(date) {
            var event = events[date];
            alert(event.text ,"Event on " + date);
        }
    });

title on date 02/14/2011 and 02/18/2011 is perfectly working because of beforeShowDay but when I am doing the same thing in onSelect it is showing undefined.Thanks in advance......Thanks

2012-04-04 05:54
by Ankur Verma


1

The type of the resulting date in the onSelect handler (String) is different from the one in the beforeShowDay handler (Date). Replace the first line only of your onSelect handler with:

var event = events[new Date(date)];

P.S.: only the first parameter of the alert will be shown

2012-04-04 06:14
by scessor
thanks it worked for me..I never thought it would be that much simple - Ankur Verma 2012-04-04 06:28
Ads