DOCTYPE html html body onload init script type text javascript functio

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html>
<body onload="init()">
<script type="text/javascript">
function daysInMonth(iMonth, iYear) {
return 32 - new Date(iYear, iMonth, 32).getDate();
}
function isWeekday(year, month, day) {
var day = new Date(year, month, day).getDay();
return day !=0 && day !=6;
}
function getWeekdaysInMonth(month, year) {
var days = daysInMonth(month, year);
var weekdays = 0;
for(var i=0; i< days; i++) {
if (isWeekday(year, month, i+1)) weekdays++;
}
return weekdays;
}
function updateDays(month) {
document.getElementById('daysInput').value = getWeekdaysInMonth(month, new Date().getFullYear());
}
function init () {
updateDays(0);
}
</script>
<form>
<select onchange="updateDays(this.value)">
<option value="0">Янв</option>
<option value="1">Фев</option>
<option value="2">Мар</option>
<option value="3">Апр</option>
<option value="4">Май</option>
<option value="5">Июн</option>
<option value="6">Июл</option>
<option value="7">Авг</option>
<option value="8">Сен</option>
<option value="9">Окт</option>
<option value="10">Ноя</option>
<option value="11">Дек</option>
</select>
<input type="text" id="daysInput" value="" />
</form>
</body>
</html>