kaze kaze - 1 month ago 10x
jQuery Question

Set initial value in datepicker with jquery?

I'm trying to set an initial value in my jquery ui datepicker. I've tried several different ways, but nothing seems to display the date, it's empty.

var idag = new Date();
$("#txtFrom").datepicker("setDate", idag - 2);
$("#txtTom").datepicker("setDate", idag);


this simple example works for me...


<input type="text" id="datepicker">


var $datepicker = $('#datepicker');
$datepicker.datepicker('setDate', new Date());

i was able to createthis by simple looking @ the manual and read the explanation of setDate:

.datepicker( "setDate" , date )
Sets the current date for the datepicker. The new date may be a Date object or a string in the current date format (e.g. '01/26/2009'), a number of days from today (e.g. +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, e.g. '+1m +7d'), or null to clear the selected date.