jQuery datepicker display year month only
14,405
This code is working flawlessly for me:
$(function()
{
$(".monthPicker").datepicker({
dateFormat: 'MM yy',
changeMonth: true,
changeYear: true,
showButtonPanel: true,
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).val($.datepicker.formatDate('MM yy', new Date(year, month, 1)));
}
});
$(".monthPicker").focus(function () {
$(".ui-datepicker-calendar").hide();
$("#ui-datepicker-div").position({
my: "center top",
at: "center bottom",
of: $(this)
});
});
});
<label for="month">Month: </label>
<input type="text" id="month" name="month" class="monthPicker" />
Author by
Fabio
Updated on June 04, 2022Comments
-
Fabio almost 2 years
I am using datepicker to select year-month only. I filter out the day part like so:
$(el).datepicker( {changeMonth: true, changeYear: true, dateFormat:'yymm' } );
The code comes from the dataInit option in jqGrid. When the user clicks in a day only the year-month is passed back to the input box.
Is there any way to just show months where the days are?
Thanks.