Hello, I am programming a system in which it calculates the average of some fields. The point is that not always all values will be reported and the average should calculate the fields in which there are values, ie the calculation of the mean will vary according to the fields yesterday has value.
HTML
<form name="formMediasETEs" method="post" action="AdicionarVazao.php">
<tr class="tabela_dados">
<td>
<input name="data" style="text-align:center; width:150px" style="font-size:10px" type="date" id="data" value="" />
</td>
<td>
<input name="oito" type="text" id="oito" onblur="ver()" style="text-align:center; width: 60px" value="" />
</td>
<td>
<input name="nove" type="text" id="nove" style="text-align:center; width: 60px" value="" />
</td>
<td>
<input name="dez" type="text" id="dez" style="text-align:center; width: 60px" value="" />
</td>
<td>
<input name="onze" type="text" id="onze" style="text-align:center; width: 60px" value="" />
</td>
<td>
<input name="doze" type="text" id="doze" style="text-align:center; width: 60px" value="" />
</td>
<td>
<input name="treze" type="text" id="treze" style="text-align:center; width: 60px" value="" />
</td>
<td>
<input name="quatorze" type="text" id="quatorze" style="text-align:center; width: 60px" value="" />
</td>
<td>
<input name="quinze" type="text" id="quinze" style="text-align:center; width: 60px" value="" />
</td>
<td>
<input name="d_seis" type="text" id="d_seis" style="text-align:center; width: 60px" value="" />
</td>
<td>
<input name="d_sete" type="text" id="d_sete" style="text-align:center; width: 60px" value="" />
</td>
<td>
<input name="d_oito" type="text" onblur="calcularMediaQLSETES()" id="d_oito" style="text-align:center; width: 60px" value="" />
</td>
</tr>
JavaScript
function calcularMediaQLSETES() {
var q2 = document.forms['formMediasETEs']['oito'].value;
var q3 = document.forms['formMediasETEs']['nove'].value;
var q4 = document.forms['formMediasETEs']['dez'].value;
var q5 = document.forms['formMediasETEs']['onze'].value;
var q23 = document.forms['formMediasETEs']['doze'].value;
var q6 = document.forms['formMediasETEs']['treze'].value;
var q7 = document.forms['formMediasETEs']['quatorze'].value;
var q8 = document.forms['formMediasETEs']['quinze'].value;
var q9 = document.forms['formMediasETEs']['d_seis'].value;
var q10 = document.forms['formMediasETEs']['d_sete'].value;
var q11 = document.forms['formMediasETEs']['d_oito'].value;
var mqls = (parseFloat(q2) + parseFloat(q3) + parseFloat(q4) +
parseFloat(q5) + parseFloat(q23) + parseFloat(q6) + parseFloat(q7) +
parseFloat(q8) + parseFloat(q9) + parseFloat(q10) + parseFloat(q11)) / 11;
document.forms['formMediasETEs']['mediaQ_ls'].value = mqls.toFixed(2);
}
Thank you!