Ver Mensaje Individual
  #8 (permalink)  
Antiguo 24/12/2012, 04:33
carlosuc99
 
Fecha de Ingreso: junio-2011
Mensajes: 342
Antigüedad: 12 años, 10 meses
Puntos: 5
Exclamación Respuesta: Problema con menús dependendientes

Cita:
Iniciado por David Ver Mensaje
Pregunto, ¿qué parte de esa fila de la tabla es la que va a cambiar por cada elemento seleccionado? Te digo esto porque usar innerHTML y elementos que no sean filas como nodos primarios en una tabla te va a dar problemas. Te sugiero que tengas esa fila ya colocada en el HTML (oculta) y cuando recibas la respuesta de la petición solo cambies lo necesario y lo muestras.
Realmente no lo reemplazo por nada visible lo reemplazo por:

Código PHP:
Ver original
  1. <tr><td id="classes" ></td></tr>

He modificado alguna cosa en los archivos y quedan así:

new_aircraft.php

Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <link rel="STYLESHEET" type="text/css" href="./style.css">
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Insert Aircraft</title>
  7. </head>
  8. <body>
  9. <script>
  10. //Ajax Script
  11. function require(){
  12.     try{
  13.     req = new XMLHttpRequest();
  14.     }catch(err1){
  15.         try{
  16.         req = new ActiveXObject("Microsoft.XMLHTTP");
  17.         }catch(err2){
  18.             try{
  19.             req = new ActiveXObject("Msxml2.XMLHTTP");
  20.             }catch(err3){
  21.             req = false;
  22.             }
  23.         }
  24.     }
  25. return req;
  26. }
  27.  
  28.  
  29. var request = require();
  30.  
  31. function callAjax(){
  32. var ramdom = parseInt(Math.random()*999999999);
  33. valor = document.getElementById("numberclasses").value;
  34. var url="classes.php?Value="+valor+"&r="+ramdom;
  35. request.open("GET",url,true);
  36. request.onreadystatechange = answerAjax;
  37. request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  38. request.send(null);
  39. }
  40.  
  41. function answerAjax(){
  42.  
  43.     if(request.readyState==4){
  44.         if(request.status==200){
  45.         //alert(request.responseText);
  46.         document.getElementById("classes").innerHTML=request.responseText;
  47.         }else{
  48.         alert("ha ocurrido un error"+request.statusText);
  49.         }
  50.     }
  51. }
  52.  
  53. </script>
  54. <?
  55.  
  56. $boton = $_POST['enviar'];
  57. $nombre = $_POST['nombre'];
  58. $precio = $_POST['precio'];
  59. $pax = $_POST['pax'];
  60. $ICAO = $_POST['ICAO'];
  61.  
  62. if($boton == 'Insertar')
  63. {
  64.     include('./db.inc.php');
  65.    
  66.     $ICAO = strtoupper($ICAO);     
  67.     mysql_query("INSERT INTO flota(ICAO, nombre, precio, capacidad) VALUES('$ICAO', '$nombre', '$precio', '$pax')") or die('<h4 style="color: red;">Ha habido un problema con la insercion.</h4>');
  68.    
  69.     mysql_close();
  70.    
  71.     echo '<h3 style="color: green;">Aeronave adquirida correctamente.<h3/>';
  72. }
  73. else
  74. {
  75.     ?>
  76.     <form action="insertar-modelo.php" method="post" enctype="application/x-www-form-urlencoded">
  77.     <table>
  78.     <tr><td class=Forms>ICAO: </td><td><input type="text" value="" name="ICAO" /></td></tr>
  79.     <tr><td class=Forms>Name: </td><td><input type="text" value="Airbus A320" name="nombre" /></td></tr>
  80.     <tr><td class=Forms>Price: </td><td><input maxlength="9" value="1000000" type="text" name="precio" /> €</td></tr>
  81.  
  82.     <tr><td class=Forms>Number Classes: </td></td><td><select name="numberclasses" id="numberclasses" onchange="callAjax()">
  83.         <option>Select Number of Classes</option>
  84.         <?php
  85.         echo'<option value="1">One</option>';
  86.         ?>
  87.     </select></td></tr>
  88.  
  89.  
  90. <tr><td id="classes" ></td></tr>
  91.  
  92.     <tr><td class=Forms>Capacidad: </td><td><input maxlength="3" value="150" type="text" name="pax" /> pasajeros</td></tr>
  93.     </table><br />
  94.     <input type="submit" name="enviar" value="Insertar"/>
  95.     </form>
  96.     <?
  97. }
  98. ?>
  99. </body>
  100. </html>

classes.php

Código PHP:
Ver original
  1. <?php
  2. $value = $_GET['Value'];
  3.  
  4. if($value == 1){
  5.  
  6.  
  7.     ?>
  8.  
  9.  
  10. <thead>
  11.     <td class=Forms>First Class: </td><td><input maxlength="3" value="150" type="text" name="pax" /></td>
  12. </thead>
  13.  
  14.    
  15. <?php
  16. }
  17.  
  18. ?>

Ahora se ve así:



Alguien sabe como lo puedo arreglar?