title: select box based on another select box value php
body: <p>I'm using ajax to do my select box, however the second select box didn't show any value when I choose the 1st select box. How can I display the value on the 2nd select box?</p>
  
  <p><strong>index.php (jQuery):</strong></p>
  
  <pre><code>$(document).ready(function(){
      $('#brand').on('change',function(){ 
          var brand = $(this).val();
          if(brand){
              $.ajax({
                  type:'POST',
                  url:'ajax_city.php',
                  data:'brand='+brand,
                  success:function(html){
                      $('#outlet').html(html);
                  }
              }); 
          }else{
              $('#outlet').html('&lt;option value=""&gt;Select OUTLET first&lt;/option&gt;');
          }
      });
  });
  </code></pre>
  
  <p><strong>index.php (Html/php)</strong></p>
  
  <pre><code>        &lt;select class="brand" style="width:200px" id="brand" name="brand" &gt;
              &lt;?php $i = 0;
              while (!$br-&gt;EOF) {
                  $fv = $br-&gt;Fields("mBrand");
                  $name = $fv-&gt;value;
                  echo '&lt;option value="' . trim($name) . '"&gt;&lt;b&gt;' . $name . '&lt;/b&gt;&lt;/option&gt;';
                  $br-&gt;MoveNext();
              }
              ?&gt;
          &lt;/select&gt;
          &lt;input type="hidden" name="loc" id="loc"&gt;
      &lt;/td&gt;
  &lt;/div&gt;
  &lt;li class="form-line" id="id_19"&gt;
      &lt;label class="form-label-left" id="label_19" for="input_19"&gt;  Outlet  &lt;/label&gt;
      &lt;div id="cid_20" class="form-input"&gt;
      &lt;br&gt;&lt;br&gt;
      &lt;select class="outlet" name="outlet" id="outlet" style="width:200px" &gt;
          &lt;option value=""&gt;--Select outlet--&lt;/option&gt;
      &lt;/select&gt;
  </code></pre>
  
  <p><strong>ajax_city.php:</strong></p>
  
  <pre><code>if(isset($_POST["brand"])&amp;&amp;!empty($_POST["brand"]))
  {
  $brand=$_POST['brand'];
  $rb = $itdeptconn-&gt;Execute("SELECT DISTINCT mOutlet FROM [IT_Dept].[dbo].[mstOutlet] WHERE mBrand='".$brand."'");
  //$sql=mysql_query("select b.id,b.data from data_parent a,data b where b.id=a.did and parent='$id'");
  
  echo '&lt;option value=""&gt;Select Outlet&lt;/option&gt;';
                                  while (!$rb-&gt;EOF) {
  
                                      $fv = $rb-&gt;Fields("mOutlet");
                                      $name = $fv-&gt;value;
  
                                      echo '&lt;option value="' . trim($name) . '"&gt;&lt;b&gt;' . $name . '&lt;/b&gt;&lt;/option&gt;';
                                      $rb-&gt;MoveNext();
                                  }
  }
                ?&gt;
  </code></pre>