Ver Mensaje Individual
  #3 (permalink)  
Antiguo 29/10/2010, 01:54
gspablo
 
Fecha de Ingreso: octubre-2009
Mensajes: 223
Antigüedad: 14 años, 6 meses
Puntos: 2
Respuesta: Select dependientes

He conseguido que sean totalmente dependientes los 3, un problemilla es que cuando seleccionas los 3 y luego vuelves al primero, sigue apareciendo el tercero en pantalla, cuando deberia eliminarse, ya que el valor del segundo select en el momento del submit no está vacio

Código HTML:
Ver original
  1. <form name="formulario" method="post" action="">
  2. <select name="categorie1" id="categorie1" OnChange="submit()">
  3.  
  4. <option id="0">All provincies</option>
  5. <?php
  6. for($i=0;$i<=2;$i++)
  7. {
  8.     if($_POST['categorie1'] == $categorie[$i][1])
  9.         echo "<option id=".$categorie[$i][0]." selected>".$categorie[$i][1]."</option>";
  10.     else
  11.         echo "<option id=".$categorie[$i][0].">".$categorie[$i][1]."</option>";
  12. }
  13. echo "</select>";
  14.  
  15. if(  ($_POST['categorie1']) || ($_POST['categorie2'])   )
  16. {
  17.     if(  $_POST['categorie1'] != 'All provincies' )
  18.     {
  19.         $id = getfield('categorie_id','categorie',"where naam='".$_POST['categorie1']."'");
  20.         $categorie2 = getrows('categorie_id2','c12',"where categorie_id=".$id."");
  21.         echo "<select name='categorie2' id='categorie2' OnChange='submit()'>";
  22.         echo "<option id='0'>All provincie</option>";
  23.         for($j=0;$j<count($categorie2);$j++)
  24.         {
  25.             $categorienaam= getrow('Naam','categorie2',"where categorie_id2=".$categorie2[$j][0]."");
  26.         if($categorienaam[0]==$_POST['categorie2'])
  27.             echo "<option id=".$categorienaam[0]." selected>".$categorienaam[0]."</option>";
  28.         else
  29.             echo "<option id=".$categorienaam[0]." >".$categorienaam[0]."</option>";
  30.         }
  31.         echo "</select>";
  32.     }
  33. }
  34. if($_POST['categorie2'] && $_POST['categorie2'] != 'All provincie' && $_POST['categorie1'] != 'All provincies')
  35. {
  36.     $idb = getfield('categorie_id2','categorie2',"where naam='".$_POST['categorie2']."'");
  37.     $categorie3 = getrows('categorie_id3','c23',"where categorie_id2=".$idb."");
  38.  
  39. echo "<select>";
  40. echo "<option id='0'>All city</option>";
  41. for($j=0;$j<count($categorie3);$j++)
  42.     {
  43.     $categorienaamb= getrow('Naam','categorie3',"where categorie_id3=".$categorie3[$j][0]."");
  44.     echo "<option id=".$categorienaamb[0].">".$categorienaamb[0]."</option>";
  45.     }
  46. echo "</select>";
  47. }
  48. ?>
  49.  
  50.  
  51. </form>

Última edición por gspablo; 29/10/2010 a las 02:45