Chaudhry Mohsin Ali Chaudhry Mohsin Ali - 4 years ago 123
jQuery Question

Default value for jquery date picker

I have some questions regarding jQuery UI date picker.

1 - Is there an option to have a default value? What I am trying to do is pre-filled my input text type with today's date.

2 - If I put the type = "Date" instead of type = "Text" and then use jquery time picker on it, I get this error when I select the date.

The specified value '02/18/2015' does not conform to the required format, 'yyyy-MM-dd.'


How do I solve this?

Answer Source

To create the datepicker and set the date. you can assign today's date by new Date(). You can set input type=text or type=date.

$('.datepicker').datepicker({ 
     dateFormat: 'dd-mm-yy'
     }).datepicker("setDate", new Date());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download