mercredi 10 août 2016

Make Select form are related each other in Laravel

in there i have 3 select input type i want make it related each other.

here my view :

<div class="form-group">
  <label for="">Location</label>
  <!-- <input id="geocomplete" type="text" name="location" placeholder="Type in an address" class="form-control" /> -->
  <select name='locations' class="form-control" id="map" required>
  <option value='' >- Location -</option>
    <?php 
      $zone = DB::table("zone")->get();
      foreach($zone as $zones) {
      echo "<option value='$zones->id'>$zones->zone</option>";
    }
    ?>
  </select>
</div>
<div class="form-group">
  <label for="">Location</label>
  <!-- <input id="geocomplete" type="text" name="location" placeholder="Type in an address" class="form-control" /> -->
  <select name='location' class="form-control" id="map" required>
  <option value='' >- Location -</option>
    <?php 
      $zonets = DB::table("zonets")->get();
      foreach($zonets as $zonetss) {
        if($zonetss->id_zone == $zone->id){
          echo "<option value='$zonetss->id'>$zonetss->location</option>";
        }
      }
    ?>
  </select>
</div>
<div class="form-group">
  <label for="">Location</label>
  <!-- <input id="geocomplete" type="text" name="location" placeholder="Type in an address" class="form-control" /> -->
  <select name='location_1' class="form-control" id="map" required>
  <option value='' >- Location -</option>
    <?php 
      $airport = DB::table("airport")->get();
      foreach($airport as $airports) {
      echo "<option value='$airports->id'>$airports->loc_airport</option>";
      }
    ?>
  </select>
</div>

this my table :

  • table for zone :

first

  • table for zonets : here

  • and this my table for airport :

here

in there i want to make the select is related.

for example :

in select = zone i choose Jakarta (id = 3)

and then i want make zonets is only show data with id_zone = 3

and after that its same with the zonets, airport is only show data with the data with id_zonets same with zonets where i choose it.

I hope someone can help me, and make my script is work..



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire