title: populate dropdown select using ajax or jquery
body: <p>I have two dropdown boxes and what I want to do is when I select from the 1st dropdown the value of the 1st dropdown will be able to get by the 2nd dropdown so it will be the basis of the 2nd dropdown to its query.</p>
  
  <pre><code>&lt;tr&gt;
      &lt;td&gt;&lt;div class="captionbold"&gt;OR Book Type&lt;/div&gt;&lt;/td&gt;
      &lt;td colspan="3"&gt;&lt;div align="left"&gt;
          &lt;span class="custom-dropdown custom-dropdown--white custom-dropdown--small"&gt;
          &lt;select class="custom-dropdown__select custom-dropdown__select--white"  name="txtorbooktype" style="width:220px;"&gt;
           &lt;option&gt;-&lt;/option&gt;
           &lt;option value='0' &lt;?php if($txtorbooktype=='0'){echo 'selected';} ?&gt;&gt;
              Real Property Tax Administration System&lt;/option&gt;
           &lt;option value='1' &lt;?php if($txtorbooktype=='1'){echo 'selected';} ?&gt;&gt;
              Business Permit and Licensing&lt;/option&gt;
           &lt;option value='2' &lt;?php if($txtorbooktype=='2'){echo 'selected';} ?&gt;&gt;
              Others Transaction&lt;/option&gt;
          &lt;/select&gt;
          &lt;/span&gt;
      &lt;/div&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;
      &lt;td&gt;&lt;div class="captionbold"&gt;OR Book&lt;/div&gt;&lt;/td&gt;
      &lt;td&gt;&lt;div align="left"&gt;
          &lt;span class="custom-dropdown custom-dropdown--white custom-dropdown--small"&gt;
          &lt;select class="custom-dropdown__select custom-dropdown__select--white"  name="txtorbookfromto" style="width:200px;"&gt;
          &lt;?php 
              $sql = "SELECT orbookcode, concat(orbookfrom,' - ',orbookto) as orbookfromto FROM rorbookinfo where orbooktype = '".$_POST['txtorbooktype']."'  and status = '0'";
              include_once rootpathphp.'/lib/config.php';
              $con = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);
              if (!$con)
              {
                die('Could not connect: ' . mysqli_error($con));
              }
  
              mysqli_select_db($con,"ajax_demo");
              $result = mysqli_query($con,$sql);                
              while($row = mysqli_fetch_array($result))
              {
                  $default = '';          
                  if($row['orbookcode']==$txtorbookfromto) 
                  {
                      $default = 'selected';
                  }
                  echo $default;
                  echo " &lt;option ".$default." value='".$row['orbookcode']."'&gt;".$row['orbookfromto']."&lt;/option&gt;";
              }
              mysqli_close($con);
              ?&gt;
          &lt;/select&gt;
          &lt;/span&gt;
      &lt;/div&gt;&lt;/td&gt;
    &lt;/tr&gt;
  </code></pre>