jquery.datePicker multi month example: showing how you can create a custom "multi month" date picker which shows two consecutive months

< date picker home

Deprecated: see the jquery.datePickerMultiMonth.js plugin plugin!

The following example displays how you can create a "multi month" date picker which shows two consecutive months and allows you to pick one date with them. It also shows how flexible the plugin is as this is achieved without modifying the plugin code at all and is instead implemented in the context of the page where it is necessary (which means it can be easily customised to behave exactly as you require in a given situation).

This will be replaced with the multimonth select

Page sourcecode

$(function()
{
	// create the left hand datePicker and add the relevant event listeners to sync it to the right hand one...
	$date1 = $('<div />')
		.datePicker({inline:true})
		.bind(
			'dpMonthChanged',
			function(event, displayedMonth, displayedYear)
			{
				$date2.dpSetDisplayedMonth(displayedMonth+1, displayedYear);
			}
		)
		.bind(
			'dateSelected',
			function(event, date, $td, status)
			{
				$date2.dpSetSelected(date.asString(), status, false);
			}
		);
	// remove the "forward" navigation from the first date picker
	$('.dp-nav-next', $date1).html('');
	// create the right hand datePicker and add the relevant event listeners to sync it to the left hand one...
	$date2 = $('<div />')
		.datePicker({inline:true})
		.bind(
			'dpMonthChanged',
			function(event, displayedMonth, displayedYear)
			{
				$date1.dpSetDisplayedMonth(displayedMonth-1, displayedYear);
			}
		)
		.bind(
			'dateSelected',
			function(event, date, $td, status)
			{
				$date1.dpSetSelected(date.asString(), status, false);
			}
		);
	// remove the "backward" navigation from the first date picker
	$('.dp-nav-prev', $date2).html('');
	// initialise the date pickers to consecutive months ($date1 defaults to this month so set $date2 to next month)
	var now = new Date();
	$date2.dpSetDisplayedMonth(now.getMonth()+1, now.getFullYear());
	// add the generated combined plugin to the document
	$('#multimonth').html('').append($date1, $date2);
});

Page CSS

#multimonth {
	border: 2px solid #000;
	overflow: auto;
	float: left;
}
.dp-applied {
	float: left;
}
table.jCalendar {
	border: none;
}
.dp-popup-inline {
	height: 160px;
}