I am trying to divide the code to four function
Second. The Smallest does not work
Third when any of 10 Grade is not between 0 and 100 the alert box say that Grade (Number of Grade) is not a number between 0 and 100 Please correct!
for example Grade 5 is not a number between 0 and 100 Please correct !
Here is the code...........
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"[URL="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"][U][COLOR=#777777]http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd[/COLOR][/U][/URL]">
<html xmlns = "[URL="http://www.w3.org/1999/xhtml"][U][COLOR=#777777]http://www.w3.org/1999/xhtml[/COLOR][/U][/URL]">
<head>
<title>Array Processing</title>
<script>
function doProcess() {
var fields=document.forms[0].getElementsByTagName('INPUT');
var val=0;
var min=0;
var max=0;
var total=0;
for (var i=0;i<fields.length;i++) {
if ((fields[i].type=='text')&&(fields[i].name.indexOf('number')==0)) {
val=parseInt(fields[i].value);
if ((val<0)||(val>100)) {
alert('only numbers between 0 and 100!');
return false;
}
if (isNaN(val)) {
alert('All fields have to contain numbers');
return false;
}
total+=val*1;
if (val>max) max=val;
if (val<min) min=val;
}
}
document.forms[0].sum.value = total;
document.forms[0].average.value = total / 10;
document.forms[0].smallest.value = min;
document.forms[0].largest.value = max;
}
</script>
</head>
<body>
<h1>Array Processing</h1>
<form method = "post" action = "/cgi-bin/formmail" >
<input name = "number0" type = "text" size = "4"
maxlength = "5" />
<input name = "number1" type = "text" size = "4"
maxlength = "5" />
<input name = "number2" type = "text" size = "4"
maxlength = "5" />
<input name = "number3" type = "text" size = "4"
maxlength = "5" />
<input name = "number4" type = "text" size = "4"
maxlength = "5" />
<input name = "number5" type = "text" size = "4"
maxlength = "5" />
<input name = "number6" type = "text" size = "4"
maxlength = "5" />
<input name = "number7" type = "text" size = "4"
maxlength = "5" />
<input name = "number8" type = "text" size = "4"
maxlength = "5" />
<input name = "number9" type = "text" size = "4"
maxlength = "5" />
<br><br>
<input type="button" name="click1" value="Process" onClick="doProcess()">
<p>
<label>Sum:
<input name = "sum" type = "text" size = "4"
maxlength = "10" />
<label>Average:
<input name = "average" type = "text" size = "4"
maxlength = "10" />
<label>Smallest:
<input name = "smallest" type = "text" size = "4"
maxlength = "10" />
<label>Largest:
<input name = "largest" type = "text" size = "4"
maxlength = "10" />
</form>
</body>
</html>