これがすべきことは、テキスト ボックスに入力された各数値を合計し、それを 5 で割って平均を計算することです。onchange イベント ハンドラーと 2 つの関数を使用し、その結果を calcAvg 関数に返す必要があります。各テキストにbox は、calcavg() という名前の関数を呼び出す onchange イベント ハンドラーを追加し、ドキュメント オブジェクトを参照することによってその関数にそのテキスト ボックスの値を渡します。performCalc() 関数で、5 つの数値の平均を計算し、その結果を calcAvg 関数に返します。
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function calcAvg(one, two, three, four, five){
var one = document.totalf.one.value;
var two = document.totalf.two.value;
var three = document.totalf.three.value;
var four = document.totalf.four.value;
var five = document.totalf.five.value;
return}
function performCalc() {
var one = document.totalf.one.value;
var two = document.totalf.two.value;
var three = document.totalf.three.value;
var four = document.totalf.four.value;
var five = document.totalf.five.value;
var res = parseFloat(one + two + three + four + five);
var calcResult = parseFloat(res/5);
return}
</script>
</head>
<body>
<form name="totalf" action="%20">
<p>Input <input type="text" value="0" name="one" onchange="calcAvg(document.totalf.one.value)"></p>
<p>Input <input type="text" value="0" name="two" onchange="calcAvg(document.totalf.two.value)"></p>
<p>Input <input type="text" value="0" name="three" onchange="calcAvg(document.totalf.three.value)" ></p>
<p>Input <input type="text" value="0" name="four" onchange="calcAvg(document.totalf.four.value)"></p>
<p>Input <input type="text" value="0" name="five" onchange="calcAvg(document.totalf.five.value)"></p>
<p>Result:<input type="text" name="res"></p>
</form>
</body>
</html>