jQuery UI Datepicker - setDate not working

Ryan Grush picture Ryan Grush · Aug 15, 2012 · Viewed 33k times · Source

I know this question has been asked on SO before, but I can't figure out what I'm missing. Here is a simple Fiddle.

The jquery:

var myDate = new Date(1978,2,11) 
$('#datepicker').datepicker('setDate', myDate);

Answer

John Koerner picture John Koerner · Aug 15, 2012

You have to initialize the datepicker first:

    $('#datepicker').datepicker();

When you pass setDate, you are calling a method which assumes the datepicker has already been initialized on that object.

http://jsfiddle.net/tbYPf/4/