Foros del Web » Programando para Internet » Javascript »

Problema con la suma del Total de los inputs

Estas en el tema de Problema con la suma del Total de los inputs en el foro de Javascript en Foros del Web. Hola, Tengo problema con la suma del Total de los inputs, la suma que hace no es la real hay diferencias que no podido determinar ...
  #1 (permalink)  
Antiguo 27/10/2006, 10:47
 
Fecha de Ingreso: noviembre-2003
Mensajes: 798
Antigüedad: 20 años, 5 meses
Puntos: 8
Problema con la suma del Total de los inputs

Hola,

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 (buttonTable)
{
    var 
row button.parentNode.parentNode;
    var 
tbody document.getElementById(Table).getElementsByTagName('tbody')[0];
    
tbody.removeChild(row);
}

function 
Suma(valorAvalorBvalorC)
{

    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 (
1i<4i++){
         
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 (
1i<4i++){
        
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> 
Gracias y saludos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:34.