JSFiddle - React, Tailwind, and code Playground

by Rupali Soni

HTML

<select id="month">
    <option>Select Month</option>
    <option value="1">January</option>
    <option value="2">February</option>
    <option value="3">March</option>
<select>
<select id="weeks" style="display:none;"></select>

JavaScript

function weekCount(year, month_number) {

    // month_number is in the range 1..12

    var firstOfMonth = new Date(year, month_number-1, 1);
    var lastOfMonth = new Date(year, month_number, 0);

    var used = firstOfMonth.getDay() + lastOfMonth.getDate();

    return Math.ceil( used / 7);
}
$('#month').change(function(){
    var selectedMonth = $(this).val();
    if(selectedMonth != "") {
        var totalWeeks = weekCount(2014, selectedMonth),
            optionsHtml = '';
        for(var i=1; i<=totalWeeks; i++) {
            optionsHtml += '<option>' + i + '</option>';   
        }
        $('#weeks').html(optionsHtml);
        $('#weeks').show();
    } else {
     $('#weeks').hide();   
    }
});