Ver Mensaje Individual
  #4 (permalink)  
Antiguo 27/09/2012, 08:41
Avatar de Alexis_Mejias
Alexis_Mejias
 
Fecha de Ingreso: enero-2005
Ubicación: Santiago
Mensajes: 77
Antigüedad: 19 años, 4 meses
Puntos: 17
Respuesta: Sumar filas en una tabla HTML

Código HTML:
function sumar(txtTotal, idFila) {
	var tabla = document.getElementById("tblPlanificacion");
	var fila = tabla.getElementsByTagName("tr");
	var sum = new Array(fila.length);
	var tot;
	var total = 0;

	for (i = 0; i < sum.length; i++)
	{
		sum[i] = 0;
		for (i = 1, tot = fila.length - 1; i < tot; i++) {
			if (idFila == i)
			{
				//total = 0;
				celdas = fila[i].getElementsByTagName("td");
				for (var j = 5, to = celdas.length - 1; j < to; j++) {
					//total = 0;
					textos = celdas[j].getElementsByTagName("input");
					for (var t = 0, tota = textos.length; t < tota; t++) {
						var num = parseInt(textos[t].value);
						if (isNaN(num)) num = 0;
						total += num;
						sum[t - 2] += num;
				}
				//textos[textos.length - s1].value = total;
				//total = 0;
				txtTotal.value = total;
				sum[t - 2] += num;
				}
			}
		}
	}
}
Y donde llamas la función deberias pasarle la fila, sumar(txtTotal, 1), sumar(txtTotal, 2), sumar(txtTotal, etc);

Saludos,
__________________
Alexis Mejias C.
Freelancer Chile - Si te sirvió puntúa positivo
Blog Personal