title: Populate combobox based on selection in another combobox in wordpress
body: <p>I want to populate combobox based on selection in another combobox in wordpress template. the options of combobox are from database. I use AJAX for get the data from combobox1 then it send to help.php. In help.php, there is a query to populate options then displayed in combobox2. But, when I select option in combobox1, combobox2 is not respond. Besides the ID from combobox1 is successfully sent. Then I realized, that the query is not executed. I think this script below</p>
  
  <pre><code>global $wpdb
  </code></pre>
  
  <p>is the main problem. So this is the question:
  1. How to make global $wpdb executed?
  2. If global $wpdb successfully executed, will combobox2 populate automatically?</p>
  
  <p>here are the form script </p>
  
  <pre><code>&lt;form method="post"&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td width="200px"&gt;
                  &lt;select name="region" id="region" style="width:200px;"&gt;
                      &lt;option value="0"&gt;-- Choose --&lt;/option&gt;
                      &lt;!-- region --&gt;
                      &lt;?php 
                      if(count( $region )){
                          foreach($region as $reg){
                              echo '&lt;option value='.$reg-&gt;id_region.'" &gt;'.$reg-&gt;name_region.'&lt;/option&gt;';
                          }
                      } else {
                          echo '&lt;option value=""&gt;No result&lt;/option&gt;';
                      }
                      ?&gt;
                  &lt;/select&gt;&lt;/td&gt;
                  &lt;td width="200px"&gt;&lt;select name="subregion" id="subregion" style="width:200px;"&gt;
                      &lt;option value="0"&gt;-- Choose --&lt;/option&gt; 
                  &lt;/select&gt;
                  &lt;/td&gt;
                  &lt;td&gt;&lt;input type="submit" value="Process" class="button" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>and here is the AJAX</p>
  
  <pre><code>&lt;script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript" &gt;      &lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function(){
      $("#region").change(function(){
          var region = $("#region").val();
          $.ajax({
              url: "&lt;?php bloginfo('template_url'); ?&gt;/help.php" ,
              data: "region=" + region,
              success: function(data){
                  $("#subregion").html(data);
              }
          });
      });
  
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>and here is the help.php</p>
  
  <pre><code>&lt;?php
  global $wpdb;
  
  $sub = $_REQUEST['region'];
  $table_name = $wpdb-&gt;prefix . 'sub_region';
  $query = "SELECT * FROM $table_name WHERE id_region='$sub' ";
  $sql = $wpdb-&gt;get_results( $query);
  
  if(count($sql)){
      foreach( $sql as $q ){
          echo '&lt;option value="'.$q-&gt;id_sub_region.'" &gt;'.$q-&gt;name_sub_region.'&lt;/option&gt;';
      }
  } else{
      echo '&lt;option value="0"&gt;-- No Result --&lt;/option&gt;';
  } ?&gt;
  </code></pre>