Código Javascript
:
Ver originalhola tengo un problema
tengo una tabla dinamica agrego filas pero necesito sumar los imput
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<SCRIPT>
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Jim Stiles | www.jdstiles.com */
function startCalc(){
interval = setInterval("calc()",1);
}
function calc(){
one = document.autoSumForm.firstBox.value;
two = document.autoSumForm.secondBox.value;
document.autoSumForm.thirdBox.value = (one * 1) * (two * 1);
}
function stopCalc(){
clearInterval(interval);
}
</SCRIPT>
<script type="text/javascript">
var contLin = 3;
function agregar() {
var tr, td, tabla;
tabla = document.getElementById('tabla');
tr = tabla.insertRow(tabla.rows.length);
td = tr.insertCell(tr.cells.length);
td.innerHTML = "<select id='sel1" + contLin + "'>"+
"<option><?php
foreach($fa as $field)
{
echo "<option value='$field[id_articulo]'>$field[nombre]</option>";
}
?>";
td = tr.insertCell(tr.cells.length);
td.innerHTML = "<input type='text' name='firstBox' id='firstBox" + contLin + "1' >";
td = tr.insertCell(tr.cells.length);
td.innerHTML = "<input type='text' name='secondBox' id='secondBox" + contLin + "2' >";
td = tr.insertCell(tr.cells.length);
td.innerHTML = "<input type='text' name='thirdBox' id='thirdBox" + contLin + "3' >";
contLin++;
}
function borrarUltima() {
ultima = document.all.tabla.rows.length - 1;
if(ultima > -1){
document.all.tabla.deleteRow(ultima);
contLin--;
}
}
</script>
</head>
<body>
<form id="autoSumForm" name="autoSumForm" method="post" action="">
<table width="100%" border="0" id="tabla">
<tr>
<td width="10%"><select name="sel1" class="campos_texto" id="sel1">
<option selected="selected">Seleccione...</option>
<?php
foreach($fa as $field)
{
echo "<option value='$field[id_articulo]'>$field[nombre]</option>";
}
?>
</select></td>
<td width="12%"><input id="firstBox" name="firstBox" type="text" class="right" onfocus="startCalc();" onblur="stopCalc();"/></td>
<td width="30%"><input name="secondBox" type="text" class="right" id="secondBox" onfocus="startCalc();" onblur="stopCalc();"/></td>
<td width="48%"><input class="right" type="text" name="thirdBox" readonly="" /></td>
</tr>
</table>
<br />
<input name="button" type="button" onclick="agregar()" value="Agregar" />
<input name="button" type="button" onclick="borrarUltima()" value="Borrar ultima" /></th>
</tr>
</form>
</body>
</html>