jQuery's datepicker allows you to highlight dates using the BeforeShowDay callback.
Is it possible to pass a second parameter to the method?
$(selector).datepicker({beforeShowDay: selectedDay});
function selectedDay(date) {
// Do stuff
return [true, 'class_name'];
}
As you can see, the parameter date
is automatically passed to the selectedDay method, thus making me unsure as to how to pass a second parameter.
Cheers.
jQuery's datepicker allows you to highlight dates using the BeforeShowDay callback.
Is it possible to pass a second parameter to the method?
$(selector).datepicker({beforeShowDay: selectedDay});
function selectedDay(date) {
// Do stuff
return [true, 'class_name'];
}
As you can see, the parameter date
is automatically passed to the selectedDay method, thus making me unsure as to how to pass a second parameter.
Cheers.
Share Improve this question asked Jul 26, 2012 at 0:26 JarrodJarrod 9,4655 gold badges60 silver badges73 bronze badges4 Answers
Reset to default 17function selectedDay(date, param ) {
// Do stuff with param
return [true, ''];
}
function doStuff(){
var param = "param_to_pass";
$(selector).datepicker({
beforeShowDay: function (date){
return selectedDay(date, param );
}
});
}
If I understand correctly, you can just create another function and pass any params you want:
function foo (param) { ... }
function selectedDay (date) {
foo(param);
return [true, 'class_name'];
}
$(selector).datepicker({beforeShowDay: selectedDay});
You can write a function which returns an array of dates
function selectedDay(date1,date2) {
// your code
return dates[];
}
and then
$(selector).datepicker({beforeShowDay: selectedDay});
just an idea, absolutely not sure if it works
I resorted to not-the-best-practice to solve my issue. I simply made the second parameter to pass a global. It'll do the job for the time being.
$(selector).datepicker({beforeShowDay: selectedDay});
var my_param = x;
function selectedDay(date) {
// Do stuff, use my_param
return [true, 'class_name'];
}