I have a jQuery datepicker and I cannot figure out how to programmatically change the month back to the current month. After making a POST
request to save the user's dates I need to return the calendar back to the current month. The calendar may be on a different month from the user playing around with different dates. I have tried setting the mindate
again but that did not work.
This is not a popup calendar.
I have a jQuery datepicker and I cannot figure out how to programmatically change the month back to the current month. After making a POST
request to save the user's dates I need to return the calendar back to the current month. The calendar may be on a different month from the user playing around with different dates. I have tried setting the mindate
again but that did not work.
This is not a popup calendar.
Share Improve this question edited Jan 25, 2014 at 1:08 Johnston asked Jan 25, 2014 at 1:00 JohnstonJohnston 20.9k22 gold badges75 silver badges123 bronze badges 3- how do you submit your form? normally direct submit or ajax? – Rami.Q Commented Jan 25, 2014 at 1:04
-
@Rami.Q I use
ajax
. This is why I am having the issue. Because the state does not change. – Johnston Commented Jan 25, 2014 at 1:05 - then on ajax success do setDate as adeneo wrote in the answer – Rami.Q Commented Jan 25, 2014 at 1:15
2 Answers
Reset to default 13Setting the datepicker back to today
$('#myDatePicker').datepicker('setDate', new Date());
setting just the month back
var date = $('#myDatePicker').datepicker('getDate');
date.setMonth( (new Date()).getMonth() );
$('#myDatePicker').datepicker('setDate', date);
FIDDLE
You can also use .val()
to set the date
$("#datepicker").val(date);