I have created a custom datepicker of month and year only . I need to get current month and upcoming months and have to hide previous months.For example current month is september than options must include sept,oct,nov,dec.
$(document).ready(function() {
$('select.month').change(function() {
var date = new Date();
var year = date.getFullYear();
console.log(year);
$('select.month option')[0].innerText = $('select option:selected').val();
$('select.month option')[0].innerHTML = $('select option:selected').val();
$("select.month").val($('select option:selected').val());
//console.log("99"+$('select.month option:selected').val());
var sd = $('select.month option:selected').val() + "-01";
var ed = moment(sd).clone().endOf('month').format('MM-DD');
var date = new Date();
var year = date.getFullYear();
//$("#year").attr=("value",year);
var aha = document.getElementById('year');
aha.innerText = year;
var startOfMonth = (year + "-" + sd);
var endOfMonth = (year + "-" + ed);
console.log(startOfMonth);
console.log(endOfMonth);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
<select class="month" placeholder="Month">
<option name="" value="" style="display:none;">MM</option>
<option name="January" id="01" value="01">January</option>
<option name="February" id="02" value="02">February</option>
<option name="March" id="03" value="03">March</option>
<option name="April" id="04" value="04">April</option>
<option name="May" id="05" value="05">May</option>
<option name="June" id="06" value="06">June</option>
<option name="July" id="07" value="07">July</option>
<option name="August" id="08" value="08">August</option>
<option name="September" id="09" value="09">September</option>
<option name="October" id="10" value="10">October</option>
<option name="November" id="11" value="11">November</option>
<option name="December" id="12" value="12">December</option>
</select>
<select>
<option id="year"></option>
</select>
2
Answers
This is simple without moment
Also you do not have ID and NAME on options