Foros del Web » Programando para Internet » Javascript »

como validar campos en una tabla dinamica---sumar inputs de la tabla dinamica

Estas en el tema de como validar campos en una tabla dinamica---sumar inputs de la tabla dinamica en el foro de Javascript en Foros del Web. @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Javascript : Ver original hola tengo un problema   tengo una tabla dinamica agrego filas pero necesito sumar los imput   <!DOCTYPE ...
  #1 (permalink)  
Antiguo 19/09/2010, 19:58
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 6 meses
Puntos: 6
como validar campos en una tabla dinamica---sumar inputs de la tabla dinamica

Código Javascript:
Ver original
  1. hola tengo un problema
  2.  
  3. tengo una tabla dinamica agrego filas pero necesito sumar los imput
  4.  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6.  
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8.  
  9. <head>
  10.  
  11. <SCRIPT>
  12. /* This script and many more are available free online at
  13. The JavaScript Source!! http://javascript.internet.com
  14. Created by: Jim Stiles | www.jdstiles.com */
  15. function startCalc(){
  16.   interval = setInterval("calc()",1);
  17. }
  18. function calc(){
  19.   one = document.autoSumForm.firstBox.value;
  20.   two = document.autoSumForm.secondBox.value;
  21.   document.autoSumForm.thirdBox.value = (one * 1) * (two * 1);
  22. }
  23. function stopCalc(){
  24.   clearInterval(interval);
  25. }
  26. </SCRIPT>
  27.  
  28.  
  29. <script type="text/javascript">
  30. var contLin = 3;
  31. function agregar() {
  32.     var tr, td, tabla;
  33.  
  34.     tabla = document.getElementById('tabla');
  35.     tr = tabla.insertRow(tabla.rows.length);
  36.     td = tr.insertCell(tr.cells.length);
  37.     td.innerHTML = "<select  id='sel1" + contLin + "'>"+
  38.                    "<option><?php
  39.                         foreach($fa as $field)
  40.                         {
  41.                             echo "<option value='$field[id_articulo]'>$field[nombre]</option>";
  42.                         }
  43.                     ?>";
  44.     td = tr.insertCell(tr.cells.length);
  45.     td.innerHTML = "<input type='text' name='firstBox' id='firstBox" + contLin + "1' >";
  46.     td = tr.insertCell(tr.cells.length);
  47.     td.innerHTML = "<input type='text' name='secondBox' id='secondBox" + contLin + "2' >";
  48.     td = tr.insertCell(tr.cells.length);
  49.     td.innerHTML = "<input type='text' name='thirdBox' id='thirdBox" + contLin + "3' >";
  50.     contLin++;
  51. }
  52. function borrarUltima() {
  53.     ultima = document.all.tabla.rows.length - 1;
  54.     if(ultima > -1){
  55.         document.all.tabla.deleteRow(ultima);
  56.         contLin--;
  57.     }
  58. }
  59. </script>
  60. </head>
  61.  
  62. <body>
  63.  
  64. <form id="autoSumForm" name="autoSumForm"  method="post" action="">
  65.  
  66. <table width="100%" border="0" id="tabla">
  67.                     <tr>
  68.                       <td width="10%"><select name="sel1" class="campos_texto" id="sel1">
  69.                         <option selected="selected">Seleccione...</option>
  70.                           <?php
  71.                         foreach($fa as $field)
  72.                         {
  73.                             echo "<option value='$field[id_articulo]'>$field[nombre]</option>";
  74.                         }
  75.                     ?>
  76.                         </select></td>
  77.                       <td width="12%"><input id="firstBox" name="firstBox" type="text" class="right" onfocus="startCalc();" onblur="stopCalc();"/></td>
  78.                       <td width="30%"><input name="secondBox" type="text" class="right" id="secondBox" onfocus="startCalc();" onblur="stopCalc();"/></td>
  79.                       <td width="48%"><input class="right" type="text" name="thirdBox" readonly="" /></td>
  80.                     </tr>
  81.                   </table>
  82.                     <br />
  83.                     <input name="button" type="button" onclick="agregar()" value="Agregar" />
  84.                     <input name="button" type="button" onclick="borrarUltima()" value="Borrar ultima" /></th>
  85.                 </tr>
  86. </form>          
  87.  
  88. </body>
  89. </html>
  #2 (permalink)  
Antiguo 19/09/2010, 20:41
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 6 meses
Puntos: 6
como validar campos en una tabla dinamica---sumar o multipli inputs de la tabla dinam

<html>
<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='sel" + contLin + "'>" +
"<option>1" +
"<option>2" +
"<option>3";
td = tr.insertCell(tr.cells.length);
td.innerHTML = "<input type='text' id='t" + contLin + "1'>";
td = tr.insertCell(tr.cells.length);
td.innerHTML = "<input type='text' id='t" + contLin + "2'>";
td = tr.insertCell(tr.cells.length);
td.innerHTML = "<input type='text' id='t" + contLin + "2'>";
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 id="tabla" border="1">
<tr>
<td><select name="sel1" id="sel1">
<option>1</option>
<option>2</option>
<option>3</option>
</select> </td>
<td><input id="firstBox" name="firstBox" type="text" class="right" onfocus="startCalc();" onblur="stopCalc();"/></td>
<td><input name="secondBox" type="text" class="right" id="secondBox" onfocus="startCalc();" onblur="stopCalc();"/></td>
<td><input class="right" type="text" name="thirdBox" readonly="" /></td>
</tr>
</table>
<br>
<input type="button" value="Agregar" onclick="agregar()">
<input type="button" value="Borrar ultima" onclick="borrarUltima()">
</form>
</body>
</html>
  #3 (permalink)  
Antiguo 20/09/2010, 08:13
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 6 meses
Puntos: 6
Respuesta: como validar campos en una tabla dinamica---sumar inputs de la tabla dinam

alguien me puede ayudar ???????????????????????????????????????????????
  #4 (permalink)  
Antiguo 20/09/2010, 11:37
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 6 meses
Puntos: 6
Respuesta: como validar campos en una tabla dinamica---sumar inputs de la tabla dinam

por favor ayudenme , me pueden dar ideas ?

gracias
  #5 (permalink)  
Antiguo 20/09/2010, 12:18
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 2 meses
Puntos: 126
Respuesta: como validar campos en una tabla dinamica---sumar inputs de la tabla dinam

Hola

Puedes por empezar a leer este post y los siguientes

Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />
  #6 (permalink)  
Antiguo 20/09/2010, 14:50
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 6 meses
Puntos: 6
Respuesta: como validar campos en una tabla dinamica---sumar inputs de la tabla dinam

necesito ayuda por favor

estoy generando una tabla dinamicamente , neceito sumar dos input pero solo me suma la primera fila , el resto nada .


gracias
  #7 (permalink)  
Antiguo 20/09/2010, 16:37
 
Fecha de Ingreso: septiembre-2010
Mensajes: 1.853
Antigüedad: 13 años, 6 meses
Puntos: 6
Respuesta: como validar campos en una tabla dinamica---sumar inputs de la tabla dinam

acudo a ustedes necesito generar la tabla dinamicamente y sumar dos inputs
en la primera fila si suma y la filas que se generan no se suman

Etiquetas: campos, dinamica, inputs, tablas
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 02:25.