Skip to content

Instantly share code, notes, and snippets.

@pandauxstudio
Created December 21, 2013 07:18
Show Gist options
  • Save pandauxstudio/8066425 to your computer and use it in GitHub Desktop.
Save pandauxstudio/8066425 to your computer and use it in GitHub Desktop.
Remove past months of months select of current year
removePastMonths = function (selectedYear, momentId) {
var curYear = (new Date).getFullYear();
var curMonth = (new Date).getMonth();
var monthSelect = $("#doneMomentMonth");
var monthSelectOptions = $("#doneMomentMonth > option");
// If current year is selected, remove past months
if (selectedYear == curYear) {
monthSelectOptions.each(function() {
var iMonth = parseInt(this.value, 10);
if (iMonth != '' && iMonth < (curMonth + 1)) {
this.remove();
}
});
} else {
monthSelect.empty();
monthSelect.append(" \
<option value=''>Select Month</option> \
<option value='1'>January</option> \
<option value='2'>February</option> \
<option value='2'>February</option> \
<option value='3'>March</option> \
<option value='4'>April</option> \
<option value='5'>May</option> \
<option value='6'>June</option> \
<option value='7'>July</option> \
<option value='8'>August</option> \
<option value='9'>September</option> \
<option value='10'>October</option> \
<option value='11'>November</option> \
<option value='12'>December</option> \
");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment