14

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);
0

1 Answer 1

33

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/

2
  • 2
    How did you knew that? If I look at the documentation api.jqueryui.com/datepicker/#method-setDate I do not see any note that it has to be called after datpicker has been first initialized.
    – Adam
    Jun 15, 2016 at 11:34
  • 1
    Worked! Been looking the 1 whole day for this! I was close to insanity! No seriously thanks man! It's not mentioned in the documentation I think.
    – Chester M
    Jul 29, 2016 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.