Ver Mensaje Individual
  #4 (permalink)  
Antiguo 12/03/2013, 03:31
kiri_vfk
 
Fecha de Ingreso: diciembre-2012
Mensajes: 17
Antigüedad: 11 años, 4 meses
Puntos: 0
Respuesta: Select dinamicos

Bueno aqui os dejo en link de lo que tengo:

http://www.goodfly.es/buscador/ajax.php

Y aqui el codigo:
Código HTML:
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. <title>Buscador ajax</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.  
  6. function ver_destinos(str)
  7. {
  8. if (str=="")
  9.   {
  10.   document.getElementById("txtHint").innerHTML="";
  11.   return;
  12.   }
  13. if (window.XMLHttpRequest)
  14.   {// code for IE7+, Firefox, Chrome, Opera, Safari
  15.   xmlhttp=new XMLHttpRequest();
  16.   }
  17. else
  18.   {// code for IE6, IE5
  19.   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  20.   }
  21. xmlhttp.onreadystatechange=function()
  22.   {
  23.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  24.    {
  25.    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  26.     }
  27.   }
  28. xmlhttp.open("GET","destinos.php?q="+str,true);
  29. xmlhttp.send();
  30. }
  31. </head>
  32. <div id="selector" style="background-color: rgb(166, 245, 135); height:60px; border-radius:10px; padding:10px; border: 1px solid darkseagreen;">
  33.     <div id="contenido" style="float: left; font-size: 18px; font-family: 'Times New Roman', Times, serif;">  
  34.          <?php
  35.          require("conexion.php");
  36.             mysql_query("SET NAMES 'utf8'");
  37.             if (!$conexion)
  38.               {
  39.               die('Could not connect: ' . mysql_error());
  40.               }
  41.             $sql="SELECT *  FROM vuelos";
  42.             $result = mysql_query($sql);
  43.             echo "<form>";
  44.             echo '<label>Seleccione su lugar de origen</label>';
  45.             echo '<select style="margin-left:15px" name="origenes" id="origenes" onchange="ver_destinos(this.value)">';
  46.             echo '<option value="">Selecciona un origen</option>';
  47.             while($row = mysql_fetch_array($result))
  48.                 {
  49.                 echo "<option value=". $row['id'] .">". $row['nombre_origen'] ."</option>";
  50.                 }
  51.              echo '</select>';
  52.              mysql_close($conexion);
  53.          echo '</form>';
  54.          echo '<br>';
  55.          ?>
  56.     </div>  <!--Ciero div contenido-->
  57.     <div id="contenido2" style="float: left; font-size: 18px; font-family: 'Times New Roman', Times, serif;">  
  58.         <div style="margin-left:30px" id="txtHint"></div>
  59.     </div>
  60. </div>  <!--Cierro el bloque selector -->
  61. <div id="miDiv" style="clear:left; padding:10px">Seleccione algun valor</div>
  62. </body>
  63. </html>

Y aqui el codigo de la pagina que llamo con ajax:
Código HTML:
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. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Documento sin título</title>
  5.  
  6. </head>
  7. <?php
  8. $q=$_GET["q"];
  9. require("conexion.php");
  10. mysql_query("SET NAMES 'utf8'");
  11. if (!$conexion)
  12.  {
  13.  die('Could not connect: ' . mysql_error());
  14.  }
  15. $sql="SELECT DISTINCT id_destinos FROM hoteles_destinos WHERE id_origen = '".$q."'";    //busco los id de los destinos posibles
  16. $result = mysql_query($sql);
  17. echo '<label>Seleccione su destino</label>';
  18. echo '<select name="combo" id="combo" onchange="cargar(this.options[this.selectedIndex].value)" style="margin-left:15px" name="destinos" id="destinos">';
  19. echo '<option value="">Elige</option>';
  20. while($row = mysql_fetch_array($result))
  21.   {
  22.       $sql2 = "SELECT nombre_origen FROM vuelos WHERE id = '".$row['id_destinos']."'";  //a partir de los id busco en la tabla de destinos el nombre
  23.       $result2 = mysql_query($sql2);
  24.       while($row2 = mysql_fetch_array($result2))   
  25.         {
  26.             echo "<option value=". $row2['id'] .">". $row2['nombre_origen'] ."</option>";   //muestro los destinos posibles para ese origen
  27.         }
  28.   }
  29. echo "</select>";
  30. mysql_close($conexion);
  31. ?>
  32.  
  33. </body>
  34. </html>
Ahora lo que no he conseguido hacer es que el segundo select me cree un tercero con las fechas disponibles; lo he intentado de todas las formas que se me han ocurrido, pero nada. Ademas de esto quiero que segun vaya selecionando cada select me ponga debajo del buscador un bloque con la info de los hoteles que encuentre con ese origen, ese destino y en la fecha selecionada.