You need to first create two select boxes as shown below:
<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>
In your Jquery code you need to get selected value of your month dropdown then use function weekCount
to count weeks in a given month with respect to given year. and then simply populate the options in another dropdown.
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();
}
});
DEMO