jQuery datepicker set selected date, on the fly

Sabya picture Sabya · Mar 3, 2009 · Viewed 372k times · Source

How can I change the selected date of jquery Date picker dynamically on the fly? I have say created a inline date picker. Then after some time, I want to reflect a different date there without recreating the datepicker from the scratch.

I tried the setDate method, but did not work, and there is not much documentation in the doc.

There is another (extended?) plugin here, but I want to use the plugin which is shipped with jquery.ui.all.js.

Answer

Ben Koehler picture Ben Koehler · Apr 15, 2009

What version of jQuery-UI are you using? I've tested the following with 1.6r6, 1.7 and 1.7.1 and it works:

//Set DatePicker to October 3, 2008
$('#dateselector').datepicker("setDate", new Date(2008,9,03) );