Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In search of JavaScript Month Picker

I'm in search of a JavaScript month selection tool. I'm already using jQuery on the website, so if it were a jQuery plugin, that would fit nicely. I'm open to other options, as well.

Basically, I'm after a simplified version of the jQuery UI Date Picker. I don't care about the day of the month, just the month and year. Using the Date Picker control feels like overkill and a kludge. I know I could just use a pair of select boxes, but that feels cluttered, and then I also need a confirmation button.

I'm envisioning a grid of either two rows of six columns, or three rows of four columns, for month selection, and current and future years across the top. (Maybe the ability to list a few years? I can't see anyone ever needing to go more than a year or two ahead, so if I could list the current and next two years, that would be swell.)

It's really just a dumbed down version of the DatePicker. Does something like this exist?

like image 913
Adam Tuttle Avatar asked Oct 12 '08 17:10

Adam Tuttle


1 Answers

Ben Koehler from this equivalent question offers a jquery ui hack that works decently. Quoted here for convenience, all credit is his.

JSFiddle of this solution

-- Here's a hack (updated with entire .html file):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js"></script>     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>     <link rel="stylesheet" type="text/css" media="screen" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/jquery-ui.css"> <script type="text/javascript"> $(function() {     $('.date-picker').datepicker( {         changeMonth: true,         changeYear: true,         showButtonPanel: true,         dateFormat: 'MM yy',         onClose: function(dateText, inst) {              var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();             var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();             $(this).datepicker('setDate', new Date(year, month, 1));         }     }); }); </script> <style> .ui-datepicker-calendar {     display: none;     } </style> </head> <body>     <label for="startDate">Date :</label>     <input name="startDate" id="startDate" class="date-picker" /> </body> </html> 
like image 95
Cory Avatar answered Sep 22 '22 19:09

Cory