I would like to set a value to input tag on which I create a datepicker. When datepicker is initialized I want to set it. Here is an some pseudo example what I want:
HTML:
<input id="test" value=""></input>
Javascript:
$('#text').datepicker({ dateFormat: 'dd.mm.yy'});
var currentDate = $('#text').datepicker('getDate');
$('#text').val(currentDate.format('dd.mm.yy'));
Thanks in advance!
If you are trying to set a default date for the datePicker plugin, you might want to use the defaultDate option.
Extract from JQuery UI/datepicker docs:
defaultDate: Date, Number, StringDefault:null
Set the date to highlight on first opening if the field is blank. Specify either an actual date via a Date object or as a string in the current dateFormat, or 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 for today.
Code examples
Initialize a datepicker with the defaultDate option specified.
Get or set the defaultDate option, after init.
All this you can easily find in the JQuery docs found here: http://docs.jquery.com