Muddsnapper
Programmer
What I want to do is update a text box with the current average of score ratings as a user enters score (numbers into text boxes) ratings for a series of questions.
I have been trying to figure this out for a couple days using different JavaScript's that I've copied but keep running into "gotchas".
So in desperation I've pieced together someone else's JavaScript (seems the most condensed of all I've looked at) with my Form. But since I don't know JavaScript I can't tie them in together. Can anyone give me a clue? Please...
I have been trying to figure this out for a couple days using different JavaScript's that I've copied but keep running into "gotchas".
So in desperation I've pieced together someone else's JavaScript (seems the most condensed of all I've looked at) with my Form. But since I don't know JavaScript I can't tie them in together. Can anyone give me a clue? Please...
Code:
<script language="JavaScript">
<!-- Another interesting Average routine I came across and worth mentioning is depicted in the code below which loops through n textboxes
// Code Start
var Sum = 0;
var DivideBy = 0;
for (i=0; i<=9; i++) {
if (getField("n."+i).value != "") {
Sum += getField("n."+i).value;
DivideBy++;
}
}
getField("Result").value = Sum/DivideBy;
// Code End ..submitted by Doron Shefer (Google Groups).
//-->
</script>
</head>
<body>
<form action="Script_Name.htm" name="surveyForm">
<table border="1">
<tr>
<td>Running Average</td>
<td>
<input name="totalBox" type="text" onfocus="this.blur()"></td>
</tr>
<tr>
<td>Type a rating number between 0 and 100</td>
<td>
<input type="text" name="question01" size="3" onblur="average (this)"></td>
</tr>
<tr>
<td>Type a rating number between 0 and 100</td>
<td>
<input type="text" name="question02" size="3" onblur="average (this)"></td>
</tr>
<tr>
<td>Type a rating number between 0 and 100</td>
<td>
<input type="text" name="question03" size="3" onblur="average (this)"></td>
</tr>
<tr>
<td>Type a rating number between 0 and 100</td>
<td>
<input type="text" name="question04" size="3" onblur="average (this)"></td>
</tr>
<tr>
<td>Type a rating number between 0 and 100</td>
<td>
<input type="text" name="question05" size="3" onblur="average (this)"></td>
</tr>
<tr>
<td>Type a rating number between 0 and 100</td>
<td>
<input type="text" name="question06" size="3" onblur="average (this)"></td>
</tr>
<tr>
<td>Type a rating number between 0 and 100</td>
<td>
<input type="text" name="question07" size="3" onblur="average (this)"></td>
</tr>
<tr>
<td>Type a rating number between 0 and 100</td>
<td>
<input type="text" name="question08" size="3" onblur="average (this)"></td>
</tr>
<tr>
<td>Type a rating number between 0 and 100</td>
<td>
<input type="text" name="question09" size="3" onblur="average (this)"></td>
</tr>
<tr>
<td>Type a rating number between 0 and 100</td>
<td>
<input type="text" name="question10" size="3" onblur="average (this)"></td>
</tr>
<tr>
<td>Type a rating number between 0 and 100</td>
<td> </td>
</tr>
<tr>
<td colspan="2" bgcolor="#FFffff" ><input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>
</body>
</html>