Jquery UI Datepicker w/Multidatepicker plugin, After Selecting a Date go back to same month as selection

Posted on 2014-02-22
Last Modified: 2014-03-10
I am using the Jquery UI Datepicker and it's working great except one last little fix needed.

The calendar pops up, and allows you to select multiple dates until you click "Done" or click outside of the datepicker popup.

What I want, is after the user clicks a date, say the calendar starts at January but the user selects a date in April. After selecting the date in april the calendar jumps back to show the month of January, where it started. I want it to show the month April so user can continue selecting in the month of April instead of having to click back to April each time they select another date.

I almost had it working by using this option in my jQuery.datepicker call:

onSelect: function(dateText, inst) { $( ".datepicker2" ).datepicker( "setDate" , dateText )

It works, by bringing the user back to the same month as just selected, However, it trumps the other dates that were previously selected, so then it only allows you to select one date instead of multiples.

It seems I just need something other than the "setDate" method but my excellent google searching skills have turned up nothing after many tries.

Thanks for any help you can give!!

My current Code looks like this:
$(function() {
  var date = new Date();
  $( ".datepicker").multiDatesPicker({
    minDate: 0, showButtonPanel: true, changeMonth: true, changeYear: true, onSelect: function(dateText, inst) { $( ".datepicker" ).datepicker( "setDate" , dateText ) }

Open in new window

Question by:tonyhhisc
  • 3
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39882281
Are you using the multidatespicker plugin on sourceforge?

Set the defaultDate in the settings param when user selects a date.
onSelect: function(dateText, inst) { inst.settings.defaultDate = dateText; }

See below for working example:
<!DOCTYPE html>
	<link rel="stylesheet" href="" />	
	<script src=""></script>
	<script src=""></script>
	<!--<script src="jquery-ui-1.10.1.custom.js"></script> -->
	<script src=""></script> 
	<form action="#">
	<p>Date: <input type="text" id="datepicker" class="datepicker"/></p>
		$(function() {
		  $( ".datepicker").multiDatesPicker({
			minDate: 0, showButtonPanel: true, changeMonth: true, changeYear: true			
				, onSelect: function(dateText, inst) { inst.settings.defaultDate = dateText; }

Open in new window

LVL 14

Accepted Solution

Pierre Cornelius earned 500 total points
ID: 39899798
Did you come right?

Author Closing Comment

ID: 39918318
This worked like a charm. Thank you so much!!
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39919690
Glad to help. Good luck.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
window.setInterval not firing 7 31
Download a website to hdd 2 51
Clear single text form value in jquery 2 30
jQuery not working on ELSE... why? 2 25
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now