Ver Mensaje Individual
  #4 (permalink)  
Antiguo 04/07/2012, 06:40
Avatar de vicram10
vicram10
 
Fecha de Ingreso: enero-2009
Ubicación: Asuncion
Mensajes: 326
Antigüedad: 15 años, 3 meses
Puntos: 27
Respuesta: Actualizar datos de tabla dinámica

y no te sera mejor traer ya en la consulta SQL el total?.. asi ya se actualizara de forma automatica.. sino seria agregar con javascript para que vuelva a sumar los nuevos valores y que se refleje el resultado.. con jquery seria facil..

Te dejo un ejemplo con jquery...

index.php

Código HTML:
Ver original
  1. <!DOCTYPE html>
  2. <html lang="es">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Recalculo Jquery</title>
  5. </head>
  6. <form name="fcalculo" id="fcalculo" action="calcular.php" method="post">
  7.     <h2>Nro. 1:</h2>
  8.     <input type="text" name="nro_1" id="nro_1" value="<?php echo !empty($nro_1) ? $nro_1 : ''; ?>" />
  9.     <h2>Nro. 2:</h2>
  10.     <input type="text" name="nro_2" id="nro_2" value="<?php echo !empty($nro_2) ? $nro_2 : ''; ?>" />
  11.     <br />
  12.     <input type="submit" name="btncalcular" id="btncalcular" value="Calcular">
  13. </form>
  14. <br />
  15. <div id="resultado"></div>
  16. <!-- llamamos al jquery -->
  17. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
  18. <script src="http://projects.ramirezmedina.com/worldnavi/rmi/js/jquery.form.js" type="text/javascript"></script>
  19. <!-- aqui le decimos que queremos hacer -->
  20. <script type="text/javascript">
  21.     $(document).ready(function() {
  22.         $('#btncalcular').live('click', function(){
  23.             $("#resultado").append('<img src="http://projects.ramirezmedina.com/worldnavi/rmi/images/cargando.gif" />');
  24.             $("#fcalculo").ajaxForm({
  25.                 target: '#resultado'
  26.             }).submit();           
  27.         });
  28.     });
  29. </body>
  30. </html>

calcular.php

Código PHP:
Ver original
  1. <?php
  2. //aca realizamos el calculo para mostrarlo luego
  3. if (isset($_POST['btncalcular']))
  4. {
  5.     $nro_1 = !empty($_POST['nro_1']) ? (int) $_POST['nro_1'] : 0;
  6.     $nro_2 = !empty($_POST['nro_2']) ? (int) $_POST['nro_2'] : 0;
  7.     $calculo = $nro_1 * $nro_2;
  8.     echo '<span style="font-weight:bold;">Resultado:</span>&nbsp;',$calculo;
  9. }
  10. ?>

Se debe tener el ultimo jquery.min.js y jquery.form.js

Última edición por vicram10; 04/07/2012 a las 07:23