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,565
  • 2
  • 21
  • 42
Aamir
  • 2,173
  • 1
  • 29
  • 58

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
  • 642
  • 6
  • 22
3

Try:

$("#companybegindate").datepicker( "setDate" , "2016-06-20" );
Jayesh Chitroda
  • 4,987
  • 13
  • 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
  • 321
  • 1
  • 6
  • 14
0

you can add another property

defaultDate: new Date(2008,9,03)

to you object

check out this fiddle

Afsar
  • 3,104
  • 2
  • 25
  • 35