How to launch the beforeShowDay of DatePicker from another function How to launch the beforeShowDay of DatePicker from another function ajax ajax

How to launch the beforeShowDay of DatePicker from another function


beforeShowDay is an event that is fired by datepicker before a day is rendered. You can use it to customize how the cell containing the day is displayed, e.g. you can turn it red to indicate blocked dates.

From what I understand from your question, you can call the datapicker.refresh() method to indicate that the freeDate variable has changed (by an AJAX response for example) and the calendar needs to be rendered again.

Edit

I believe this is the code for your dropdown, seems like it uses ajax:

$('#myList').change(...

In the success callback, you have:

freeDate = eval(data);

This is where the freeDate changes and this is probably where you should call the .refresh() method. Note that AJAX is asynchronous by default so there is some delay between selecting value and the success event callback.

And here is how you call a method on an existing datepicker:

...freeDate = eval(data);$("#myDiv").datepicker("refresh");...


I would say you should probably define that function outside of the datepicker call and then your change and the datepicker can call that function.

EDIT: Clarification added.

Trying to figure out how the plugin works to call the function is probably more work than it's worth. You can define the function separately and then just pass it to the plugin. Then your dropdown change event can call that independent method.

Something like this:

function doMyThing(dateToShow){   // do stuff}$("#myDiv").datepicker({    ...    beforeShowDay: function(dateToShow){        doMyThing(dateToShow);    }});  $('#myList').change(function () {    doMyThing(dateToShow);});  

The only thing I'm unsure of is what you'll want to pass as a parameter in the onchange. Since it's not an action of clicking on a date, I don't know what "dateToShow" should be.