maxp maxp - 1 year ago 88
Javascript Question

Setting 'option' on jqueryui DatePicker clears the textbox's value?

I've highlighted the example here:

Basically, a separate event (not known at construction) needs to set

on the datepicker control. This 'clears' the textbox value which is really annoying, as the initial construction does not.

Can anyone offer a solution?


Changing line 5 to:

$("#myinput").datepicker({minDate:new Date(), maxDate: new Date()});

makes it work as expected, but is a seriously messy approach.

Answer Source

It's an issue with the format. Your initial value dd-mm-yyyy doesn't match the datepickers default format. To resolve, set the initial value to the correct format and specify the format as dateFormat when creating the datepicker.


Change to:

<input id="myinput" type="text" value="01-01-1970" />


//construct datepicker
$("#myinput").datepicker({minDate:new Date(), dateFormat : "dd-mm-yy"});
//later on, a seperate event changes the maxDate property
//but this 'clears' the existing value in the textbox!
$("#myinput").datepicker("option","maxDate", new Date());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download