title: Dependent dropdown
body: <p>i have a problem in dependent dropdown and i am not professional in this issue </p>
  
  <p>so the problem is when i choose the first one the another one doesnt get any value from database and i didnt know the solution</p>
  
  <pre><code>&lt;?php
  include 'header.php';
  require 'connection.php';
  ?&gt;
  
  &lt;div class="container"&gt;  
  &lt;form id="contact" action="add_line.php" method="post"&gt;
  &lt;center&gt; &lt;h3&gt;Add Line&lt;/h3&gt;&lt;/center&gt;
  &lt;fieldset&gt;
  &lt;?php  
  require 'connection.php';
  $query = "select * from agents";
  $result = mysqli_query($conn,$query);
  ?&gt;
  &lt;div class="select"&gt;
  &lt;select class="agents-name " name="agents-name" autofocus tabindex="1"&gt;
  &lt;option selected="selected"&gt;--Select agent--&lt;/option&gt;
  &lt;?php while ($row = mysqli_fetch_assoc($result)): ?&gt;
  &lt;option value="&lt;?php $row['id'];?&gt;"&gt;&lt;?php echo $row['name'];?&gt;&lt;/option&gt;
  &lt;?php endwhile;?&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  &lt;div class="select" &gt;
  &lt;select tabindex="1" name="sp_choosen" class="sp_choosen"             
  onChange="getState( this.value );" tabindex="2"&gt;
  &lt;option selected="selected"&gt;--Select service provider--&lt;/option&gt;
  &lt;option value="CELLCOM"&gt;CELLCOM&lt;/option&gt;
  &lt;option value="HoTMobile"&gt;HoTMobile&lt;/option&gt;
  &lt;option value="Orange"&gt;Orange&lt;/option&gt;
  &lt;option value="Pelphone"&gt;Pelphone&lt;/option&gt;
  &lt;option value="Golan"&gt;Golan&lt;/option&gt;
  &lt;option value="019"&gt;019&lt;/option&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  &lt;div class="select"&gt;
  &lt;select  id="packet_select" name="packet_chossen" tabindex="3"&gt;
  &lt;option selected="selected"&gt;--Select packet--&lt;/option&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  &lt;/fieldset&gt;
  &lt;fieldset&gt;
  &lt;input placeholder="customer name" type="text" tabindex="4"  
  name="customer_name" required &gt;
  &lt;/fieldset&gt;
  &lt;fieldset&gt;
  &lt;input placeholder="SIM_SERIAL" type="tel" tabindex="5" name="sim_serial"    
  required &gt;
  &lt;/fieldset&gt;
  &lt;fieldset&gt;
  &lt;input placeholder="phone_number" type="tel" tabindex="6" name="number"   
  required &gt;
  &lt;/fieldset&gt;
  &lt;fieldset&gt;
  &lt;label&gt;&lt;/label&gt;
  &lt;/fieldset&gt;
  &lt;fieldset&gt;
  &lt;button name="submit" type="submit" id="contact-submit" tabindex="7" &gt;Add   
  Available line&lt;/button&gt;
  &lt;/fieldset&gt;
  &lt;/form&gt; 
  &lt;/div&gt;
  &lt;script src="https://code.jquery.com/jquery-1.9.1.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
  function getState(val) {
  $.ajax({
  type: "POST",
  url: "dropdown_add_line.php",
  data:'sp='+val,
  success: function(data){
  $("#packet_select").html(data);
  }
  });
  }
  &lt;/script&gt;
  &lt;?php
  include 'footer.php';
  ?&gt;
  </code></pre>
  
  <p>and this is the dropdown_add_line.php :</p>
  
  <pre><code>&lt;?php
  require_once("connectione.php");
  $db_handle = new DBController();
  if(!empty($_POST["sp"])) {
      $sp=$_POST['sp'];
      $query ="SELECT * FROM packets p WHERE sp  LIKE '%$sp%'";
      $results = $db_handle-&gt;runQuery($query);
  ?&gt;
      &lt;option value=""&gt;--Select service provider--&lt;/option&gt;
  &lt;?php
      foreach($results as $packets) {
  ?&gt;
      &lt;option value= "&lt;?php echo $packets["id"]; ?&gt;" &gt;&lt;?php echo $packets["packet"]; ?&gt;&lt;/option&gt;
  &lt;?php
      }
  }
  ?&gt;
  </code></pre>
  
  <p>and the table name is "packets" and the columns is "id","sp","packet"  </p>