Ver Mensaje Individual
  #6 (permalink)  
Antiguo 26/03/2013, 07:26
Avatar de cuasatar
cuasatar
 
Fecha de Ingreso: junio-2011
Ubicación: Bogotá Rock City
Mensajes: 1.230
Antigüedad: 12 años, 10 meses
Puntos: 181
Respuesta: Problemas con envío de números (php y AJAX)

Revisa en el dom getelementsbytagName, no se si asi se puedan obtener sus valores,revisa la documentación. Yo suelo usar getElementByID.

En el formulario no se coloca ni metodo ni accion

Valida la entrada para que no te de la tabla de multiplicar "papa*1", "mama*5", etc. Eso te lo dejo de tarea, mira los enlaces:

http://php.net/manual/es/function.isset.php
http://www.php.net/manual/es/function.is-numeric.php
http://www.php.net/manual/es/function.is-float.php


Código HTML:
Ver original
  1. <!DOCTYPE html>
  2. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  3. <title>php while</title>
  4. <script type="text/javascript">
  5. function enviar(valor)
  6. {
  7.     var xmlhttp = new XMLHttpRequest();
  8.     xmlhttp.onreadystatechange=function()
  9.     {
  10.         if (xmlhttp.readyState==4 && xmlhttp.status==200)
  11.         {
  12.             document.getElementById("tabla").innerHTML=xmlhttp .responseText;
  13.         }
  14.     }
  15. xmlhttp.open("GET","php_while.php?i="+valor,true);
  16. xmlhttp.send();
  17. }
  18. </head>
  19. <form action="">
  20. Inserta el número del que quieres que escriba la tabla de multiplicar:
  21. <br/><input type="text" name="i" id="i"/>
  22. <br/><button type="button" onclick="enviar(document.getElementById('i').value)">OK</button>
  23. <div id="tabla"></div>
  24. </form>
  25. </body>
  26. </html>

Código PHP:
<?php
$i 
$_GET['i'];
$x 1;
echo 
"<table border='2px solid black';>";
while (
$x <= 10){
echo 
'<tr><td>'.$i.'</td><td> X </td><td>'.$x.'</td><td> = </td><td>'.($i*$x).'</td>';
$x++;
}
echo 
"</table>";
?>
__________________
Blog de humor http://elcuasatar.net63.net/

Última edición por cuasatar; 26/03/2013 a las 07:42