Tengo problema con la suma del Total de los inputs, la suma que hace no es la real hay diferencias que no podido determinar el origen.
este es el script:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Crear input file</title>
<script type="text/javascript">
<!--
var rowNumber = 0;
var grantotal2 = 0;
delRow = function (button, Table)
{
var row = button.parentNode.parentNode;
var tbody = document.getElementById(Table).getElementsByTagName('tbody')[0];
tbody.removeChild(row);
}
function Suma(valorA, valorB, valorC)
{
var Valor1 = parseInt(document.getElementById(valorA).value);
var Valor2 = parseInt(document.getElementById(valorB).value);
grantotal = parseInt(Valor1+Valor2);
grantotal2 = grantotal2+grantotal;
document.getElementById(valorC).value = grantotal;
document.getElementById('grantotal').value = grantotal2;
}
addRow = function (Table)
{
rowNumber++;
var aTable = document.getElementById(Table)
aTable.setAttribute("name",Table);
aTable.setAttribute("border",0);
var tbody = document.getElementById(Table).getElementsByTagName('tbody')[0];
tbody.setAttribute('name','TableBody');
var row = document.createElement('tr');
var cells = Array();
var inp = Array();
for (i = 1; i<4; i++){
cells[i] = document.createElement('td');
inp[i] = document.createElement('input');
}
cells[2].setAttribute('width','10px');
inp[1].setAttribute('type','text');
inp[1].setAttribute('id','valor1['+rowNumber+']');
inp[1].setAttribute('name','valor1['+rowNumber+']');
inp[1].onkeyup = function() {Suma("valor1["+rowNumber+"]", "valor2["+rowNumber+"]", "total["+rowNumber+"]") }
inp[2].setAttribute('type','text');
inp[2].setAttribute('value',0);
inp[2].setAttribute('id','valor2['+rowNumber+']');
inp[2].setAttribute('name','valor2['+rowNumber+']');
inp[2].onkeyup = function() {Suma("valor1["+rowNumber+"]", "valor2["+rowNumber+"]", "total["+rowNumber+"]") }
inp[3].setAttribute('type','text');
inp[3].setAttribute('id','total['+rowNumber+']');
inp[3].setAttribute('name','total['+rowNumber+']');
for (i = 1; i<4; i++){
cells[i].appendChild(inp[i]);
row.appendChild(cells[i]);
}
tbody.appendChild(row);
}
-->
</script>
</head>
<body>
<form name=Form1 action="index.php" method="post">
<table border="0" id="table1" name="table1">
<input type="button" value="Agregar Linea" onClick="addRow('table1');">
<tr>
<td><b>Cantidad</b></td>
<td><b>Item</b></td>
<td><b>Liquido</b></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="5" >
<tr>
<td width="100"><label><strong>Gran Total: </strong></label></td>
<td><input type="text" name="grantotal" id="grantotal" size="12" /></td>
</tr>
</table>
<input type="submit" value="Guardar" name="guardar" >
</form>
</body>
</html>