Hi. I am trying to write a function that will take 15 form fields, sum the values and divide by all the non-zero values. For example: if 12 values aare entered I want the sum to be divided by 12 for the average.
Here's my cluncky code:
function sevavg() {
Sev = eval (document.Form.Sev.value);
Sev2 = eval (document.Form.Sev2.value);
Sev3 = eval (document.Form.Sev3.value);
Sev4 = eval (document.Form.Sev3.value);
Sev5 = eval (document.Form.Sev5.value);
Sev6 = eval (document.Form.Sev6.value);
Sev7 = eval (document.Form.Sev7.value);
Sev8 = eval (document.Form.Sev8.value);
Sev9 = eval (document.Form.Sev9.value);
Sev10 = eval (document.Form.Sev10.value);
Sev11 = eval (document.Form.Sev11.value);
Sev12 = eval (document.Form.Sev12.value);
Sev13 = eval (document.Form.Sev13.value);
Sev14 = eval (document.Form.Sev14.value);
Sev15= eval (document.Form.Sev15.value);
var myData = [document.Form.Sev.value,
document.Form.Sev2.value,
document.Form.Sev3.value,
document.Form.Sev3.value,
document.Form.Sev5.value,
document.Form.Sev6.value,
document.Form.Sev7.value,
document.Form.Sev8.value,
document.Form.Sev9.value,
document.Form.Sev10.value,
document.Form.Sev11.value,
document.Form.Sev12.value,
document.Form.Sev13.value,
document.Form.Sev14.value,
document.Form.Sev15.value];
var alen = myData.length;
document.Form.sevavg.value = (Sev+Sev2+Sev3+Sev4+Sev5+Sev6+Sev7+Sev8+Sev9+Sev10+Sev11+Sev12+Sev13+Sev14+Sev15)/alen;
}
</script>
Here's my cluncky code:
function sevavg() {
Sev = eval (document.Form.Sev.value);
Sev2 = eval (document.Form.Sev2.value);
Sev3 = eval (document.Form.Sev3.value);
Sev4 = eval (document.Form.Sev3.value);
Sev5 = eval (document.Form.Sev5.value);
Sev6 = eval (document.Form.Sev6.value);
Sev7 = eval (document.Form.Sev7.value);
Sev8 = eval (document.Form.Sev8.value);
Sev9 = eval (document.Form.Sev9.value);
Sev10 = eval (document.Form.Sev10.value);
Sev11 = eval (document.Form.Sev11.value);
Sev12 = eval (document.Form.Sev12.value);
Sev13 = eval (document.Form.Sev13.value);
Sev14 = eval (document.Form.Sev14.value);
Sev15= eval (document.Form.Sev15.value);
var myData = [document.Form.Sev.value,
document.Form.Sev2.value,
document.Form.Sev3.value,
document.Form.Sev3.value,
document.Form.Sev5.value,
document.Form.Sev6.value,
document.Form.Sev7.value,
document.Form.Sev8.value,
document.Form.Sev9.value,
document.Form.Sev10.value,
document.Form.Sev11.value,
document.Form.Sev12.value,
document.Form.Sev13.value,
document.Form.Sev14.value,
document.Form.Sev15.value];
var alen = myData.length;
document.Form.sevavg.value = (Sev+Sev2+Sev3+Sev4+Sev5+Sev6+Sev7+Sev8+Sev9+Sev10+Sev11+Sev12+Sev13+Sev14+Sev15)/alen;
}
</script>