3

I'm implementing edit user functionality. This is my jquery code for datepicker

$('#companybegindate').datepicker({
    autoclose: true,
    dateFormat: 'yy',
    changeYear: true
});

And this is HTML

 <input type="text" class="form-control pull-right" name="companybegindate" id="companybegindate" value="">

My question is if I'm fetching any date from database , how can i set that date to datepicker by default ??

Suppose I'm getting '2016-06-20', how can I set this date to datepicker by default. Any help is much appreciated..Thanks.

Murad Hasan
  • 9,418
  • 2
  • 19
  • 40
Aamir
  • 2,025
  • 1
  • 28
  • 54

4 Answers4

4
<input type="text" class="form-control pull-right" name="companybegindate" id="companybegindate" value="2016-06-20">

You may set date ('2016-06-20') directly to value attribute of input so it will be a default value.

Or You may use folowing to set it with java script.

$("#companybegindate").datepicker( "setDate" , "2016-06-20" );

Maulik Kanani
  • 632
  • 5
  • 22
3

Try:

$("#companybegindate").datepicker( "setDate" , "2016-06-20" );
Jayesh Chitroda
  • 4,917
  • 12
  • 18
0

Seem be the option you search : http://api.jqueryui.com/datepicker/#option-defaultDate. In addition be sur of the date format option too.

Killan
  • 307
  • 8
  • 14
0

you can add another property

defaultDate: new Date(2008,9,03)

to you object

check out this fiddle

Afsar
  • 3,068
  • 2
  • 23
  • 33