title: Chaining select with page load/onclick event in jQuery
body: <p>I'm trying to chain two select drop-downs with the onclick event but with little success. This is what I've managed to achieve so far. </p>
  
  <p>This is my code so far:</p>
  
  <p><strong>form.php</strong></p>
  
  <pre><code>$("#dept").click(function () {
      var dept = $("#dept").val();
      var dataString = 'dept=' + dept
      $.ajax({
          type: "POST",
          url: "process.php",
          data: dataString,
          cache: false,
          success: function (html) {
             $('select.moduleCode').html();
          }
      });
  });
  
  Department    
  &lt;select name="dept" id="dept"&gt;
  &lt;option value="&lt;?php echo $loggedin_id; ?&gt;"&gt;
  &lt;?php echo $_SESSION[$thename]; ?&gt;&lt;/option&gt;
  &lt;option&gt;---------------------------------&lt;/option&gt;
  &lt;?php
  $sql = "SELECT * FROM ts_dept WHERE id&lt;&gt;:id";
  $stm = $pdo-&gt;prepare( $sql );
  $stm-&gt;execute( array( ':id' =&gt; $loggedin_id ) );
  $rows = $stm-&gt;fetchAll();
  foreach ($rows as $row) 
  {
    echo '&lt;option value="'.$row['id'].'"&gt;
    '.$row['dept'].'
    &lt;/option&gt;';
  };
  ?&gt;
  &lt;/select&gt;
  
  &lt;p&gt;
  
  Module Code
  &lt;select name="moduleCode" id="moduleCode"&gt;
  &lt;option&gt;---------------------------------&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p><strong>process.php</strong></p>
  
  <pre><code>&lt;?php
  require_once("../resources/php/connection.php");
  
  $dept_id = $_POST["dept"];
  
  $sql = "SELECT id FROM ts_module WHERE id=:id";
  $stm = $pdo-&gt;prepare( $sql );
  $stm-&gt;execute( array( ':id' =&gt; $dept_id ) );
  $rows = $stm-&gt;fetchAll();
  foreach ($rows as $row) 
  {
      echo '&lt;option&gt;'.$row['id'].'&lt;/option&gt;';
  }
  ?&gt;
  </code></pre>
  
  <p>I am trying to fill the <strong>option</strong>'s of the <strong>moduleCode</strong> drop down with values based on the selection made in the <strong>dept</strong> dropdown (this event should be initiated on page load as well. But despite the user making a selection in the <strong>dept</strong> drop down, nothing is refreshed in the <strong>moduleCode</strong> dropdown. What changes do I need to make to my code to sort this problem out?</p>