En la funcion que esta abajo solo me reconoce un text donde se debe escribir el resultado de la suma de 3 numero divididos entre 3, pero esta solo me lo hace para uno de los datos esto solo es un ejemplo del codigo real ya que el otro llena la tabla apartir de la a BD . ......alguna ayuda ....gracias
Código PHP:
<html>
<head>
<title>Calculo de promedios</title>
<script>
function pagoscl()
{
p = new Array();
p[0] = document.getElementById("pago1[]").value
p[1] = document.getElementById("pago2[]").value
p[2] = document.getElementById("pago3[]").value
p[3]=document.getElementById("prom[]")
for (i = 0, campos = p.length; i < campos; i++)
{
p[i] = (!isNaN(p[i]) && p[i] != '')? Number(p[i]): 0;
if ( p[0] != "" )
{
p[3].value = p[0] //aca se escribe el resultado
}
if ( p[0] || p[1] != "" )
{
var suma1 = p[0] + p[1];
var pg = Number(suma1 / 2);
pg = pg.toFixed(1);
pg = pg.substring(0, pg.length - 2);
p[3].value = pg //aca se escribe el resultado
}
if ( p[0] || p[1] || p[2] != "" )
{
var suma2 = p[0] + p[1] + p[2];
var pg = Number(suma2 / 3);
pg = pg.toFixed(1);
pg = pg.substring(0, pg.length - 2);
p[3].value = pg //aca se escribe el resultado
}
}
}
</script>
</head>
<body>
<form>
<table cellpadding="0" cellspacing=0 width="50%" align=center border=0>
<thead><tr><td colspan=12 align=center>Proveedores</td></tr></thead>
<thead><tr><td>Nª</td><td>Codigo</td><td>Empresa</td><td>I abono</td><td>II abono</td><td>III abono</td><td>Total</td></tr></thead>
<tr>
<td><input type="text" value="1" name="id[]" style="color:#000000; width:36px; text-align:center;border-color:#A0A0A4"></td>
<td><input type="text" value="GCrp-3" name="cod[]" style="color:#000000; width:56px; text-align:center;border-color:#A0A0A4"></td>
<td>Gonzalez Corporation</td>
<td><input name="pago1[]" id="pago1[]" onMouseDown="pagoscl(this.name)" onKeyUp="pagoscl(this.name)" style="color:#000000; width:36px; text-align:center;border-color:#A0A0A4"></td>
<td><input name="pago2[]" id="pago2[]" onMouseDown="pagoscl(this.name)" onKeyUp="pagoscl(this.name)" style="color:#000000; width:36px; text-align:center;border-color:#A0A0A4"></td>
<td><input name="pago3[]" id="pago3[]" onMouseDown="pagoscl(this.name)" onKeyUp="pagoscl(this.name)" style="color:#000000; width:36px; text-align:center;border-color:#A0A0A4"></td>
<td><input type="text" value="" name="prom[]" id="prom[]" style="color:#000000; width:36px; text-align:center;border-color:#A0A0A4"></td></tr>
<tr><td><input type="text" value="2" name="id[]" style="color:#000000; width:36px; text-align:center;border-color:#A0A0A4"></td>
<td><input type="text" value="DLz-1" name="cod[]" style="color:#000000; width:56px; text-align:center;border-color:#A0A0A4"></td>
<td>Distribuidora Lopez</td>
<td><input name="pago1[]" id="pago1[]" onMouseDown="pagoscl(this.name)" onKeyUp="pagoscl(this.name)" style="color:#000000; width:36px; text-align:center;border-color:#A0A0A4"></td>
<td><input name="pago2[]" id="pago2[]" onMouseDown="pagoscl(this.name)" onKeyUp="pagoscl(this.name)" style="color:#000000; width:36px; text-align:center;border-color:#A0A0A4"></td>
<td><input name="pago3[]" id="pago3[]" onMouseDown="pagoscl(this.name)" onKeyUp="pagoscl(this.name)" style="color:#000000; width:36px; text-align:center;border-color:#A0A0A4"></td>
<td><input type="text" value="" name="prom[]" id="prom[]" style="color:#000000; width:36px; text-align:center;border-color:#A0A0A4" ></td></tr></table>
</form>
</body>
</html>