Jonathan
Jonathan

Reputation: 2021

jquery ui datepicker setDate not working properly

I have a very simple setup which is surprisingly not working:

HTML

<input type="text" value="08/03/2016" class="datepicker" />

JS

$(document).ready(function() {
   $('.datepicker').datepicker({
       setDate: "08/03/2016"
   });
});

No matter if having input-value set or not, its always showing up October 2015 on open. Why so?

Upvotes: 0

Views: 3243

Answers (2)

Florian
Florian

Reputation: 727

You have to initialize the datepicker first:

$(function() {
    $('.datepicker').datepicker();
    $('.datepicker').datepicker("setDate",  "08/03/2016");
});

https://jsfiddle.net/n3Lapbhn/2/

Upvotes: 1

vijayP
vijayP

Reputation: 11502

Try this:

$( ".datepicker" ).datepicker( "setDate", "08/03/2016" );

Its a method call and not the option while initializing it.

Upvotes: 2

Related Questions