sur_oviy,
<html>
<head>
<script language="javascript">
var d = document;
function summ() {
var len = d.getElementsByName("rating"), el, er = 0, sum = 0;
d.getElementById("error").innerHTML = ""; d.getElementById("res").value = ""; d.getElementById("sr").value = "";
for (i = 0; i < len.length; i++) {
el = Number(len[i].value);
if (isNaN(el) || el == "" || (el < 2 || el > 5)) {
d.getElementById("error").innerHTML = "Оценка №"+(i+1)+" не является числом или не попадает в диапазон от 2 до 5!"; er = 1; break;
}
else {
sum += el;
}
}
if (er == 1) { return false; }
d.getElementById("res").value = sum;
d.getElementById("sr").value = Math.round(sum/len.length);
}
</script>
</head>
<body>
<h1 align="center">Анкета успеваемости студента</h1>
<form name="form1">
<table align="center" border="2px">
<tr><th>#</th><th>Дисциплина</th><th>Оценка</th></tr>
<tr><td>1</td><td>Математика</td><td><input type="text" size="10" maxlength="1" name="rating" onkeyup="summ()"></td></tr>
<tr><td>2</td><td>Информатика</td><td><input type="text" size="10" maxlength="1" name="rating" onkeyup="summ()"></td></tr>
<tr><td>3</td><td>Физика</td><td><input type="text" size="10" maxlength="1" name="rating" onkeyup="summ()"></td></tr>
<tr><td>4</td><td>История</td><td><input type="text" size="10" maxlength="1" name="rating" onkeyup="summ()"></td></tr>
<tr><td>5</td><td>Русский язык</td><td><input type="text" size="10" maxlength="1" name="rating" onkeyup="summ()"></td></tr>
<tr><td>6</td><td>Физкультура</td><td><input type="text" size="10" maxlength="1" name="rating" onkeyup="summ()"></td></tr>
<tr><td> </td><td>Сумма</td><td><input type="text" size="10" id="res"></td></tr>
<tr><td> </td><td>Средняя оценка</td><td><input type="text" size="10" id="sr"></td></tr>
</table><br>
<span id="error" style="color: red; width: 100%; text-align: center;"></span>
</form>
</body>
</html>