Ver Mensaje Individual
  #2 (permalink)  
Antiguo 12/05/2010, 01:40
quimfv
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 1 mes
Puntos: 574
Respuesta: suma en dinamico

Código HTML:
Ver original
  1. <SCRIPT LANGUAGE="JavaScript">
  2. <!--
  3. var row;
  4.  
  5. function doAddRow(){
  6. var table = document.getElementById('mytable')
  7. table.insertRow(table.rows.length)
  8. row = table.rows[table.rows.length-1]
  9. for(i=0;i<table.rows[0].cells.length;i++){
  10. row.insertCell(i)
  11. if(i==0)
  12. row.cells[i].innerHTML = '<input name="TextBox[i]" type="text" id="TextBox[i]" />'
  13. if(i==1)
  14. row.cells[i].innerHTML = '<input name="TextBox[i]" type="text" id="TextBox[i]" />'
  15. if(i==2)
  16. row.cells[i].innerHTML = '<input name="TextBox[i]" type="text" id="TextBox[i]" />'
  17. if(i==3)
  18. row.cells[i].innerHTML = '<input name="fono" type="text" id="Fono[i]" onkeyup="sumar(this.form)" />'
  19. }
  20. }
  21. //-->
  22.  
  23.  
  24.  
  25.  
  26. <SCRIPT LANGUAGE="JavaScript">
  27. function sumar(frm) {
  28. suma=0;
  29. for(i=0;i<frm.elements.length;i++){
  30.     if(frm.elements[i].name="fono"){
  31.         valor=parseInt(frm.elements[i].value,10);
  32.         if(!isNaN(valor)) suma+=valor;
  33.     }
  34. }
  35.  document.getElementById('suma').innerHTML = 'Total = '+ suma;
  36.  
  37. }
  38.  
  39.  
  40.  
  41. <INPUT TYPE="button" value="AGREGAR FILA" onclick="doAddRow()">
  42. <table id="mytable" border=1>
  43. <TR>
  44. <TD>NOMBRE</TD>
  45. <TD>EMPRESA</TD>
  46. <TD>CIUDAD</TD>
  47. <TD>FONO</TD>
  48. </TR>
  49. <TR>
  50. <TD> <input name="TextBox1" type="text" id="TextBox1" /></TD>
  51. <TD> <input name="TextBox2" type="text" id="TextBox2" /></TD>
  52. <TD> <input name="TextBox3" type="text" id="TextBox3" /></TD>
  53. <TD> <input name="fono" type="text" id="TextBox4"  onkeyup="sumar(this.form)"  /></TD>
  54. </TR>
  55. </form>
  56. <p id="suma">Total = 0</p>
  57. </BODY>
  58. </HTML>

Esto serviria?

Quim