title: Dynamic dropdown list
body: <ol>
  <li>subjects</li>
  <li>course</li>
  <li>chapters</li>
  </ol>
  
  <p>I want to add 2 dynamic dropdown lists, one is for subjects, and one is for course. When I select subject, courses which is added to that subject should be loaded in the course dropdown list, and then add chapters to that courses.</p>
  
  <p>How do I do that? </p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;div class="content-form-inner"&gt;
  
          &lt;div id="page-heading"&gt;Enter the details&lt;/div&gt;
          &lt;div class="form_loader" id="thisFormLoader"&gt;&lt;/div&gt;
          &lt;div id="error_message"&gt;&lt;/div&gt;
          &lt;form name="thisForm" id="thisForm" action="editchapters.php?mode=&lt;?php echo $_REQUEST['mode']; ?&gt;&amp;id=&lt;?php echo $id; ?&gt;" method="post" enctype="multipart/form-data"&gt;
              &lt;table border="0" cellpadding="0" cellspacing="0" id="id-form" &gt;
                  &lt;tr&gt;
                          &lt;th valign="top" style="width:0%"&gt;&lt;span class="required"&gt;*&lt;/span&gt;Subject&lt;/th&gt;
                          &lt;td style="width: 0%"&gt;
                          &lt;select name="subject_name" class="select-form required " style="color:#000 !important;width:200px !important"&gt;
                          &lt;option value=""&gt;Select&lt;/option&gt;
                          &lt;?php
                              $sql = "select * from mock_subject ";
                              $res = mysqli_query($dbhandle,$sql);
                              $numrows =mysqli_num_rows($res);
                              echo mysql_error();
  
                              if($numrows){
  
                                  while($obj = mysqli_fetch_object($res)){
  
                                      if($obj-&gt;status == 1){
  
                                          if($subject == $obj-&gt;id){
                                              echo '&lt;option value="'.$obj-&gt;id.'" selected&gt;'.($obj-&gt;subject_name).'&lt;/option&gt;';
                                          }
                                          else{
                                              echo '&lt;option value="'.$obj-&gt;id.'"&gt;'.($obj-&gt;subject_name).'&lt;/option&gt;';  
                                          }
                                      }
                                  }
                              }
                          ?&gt;
                          &lt;/select&gt;
                          &lt;/td&gt;
  
                          &lt;td style="width: 0%;"&gt;
                              &lt;div id="subject_id-error" class="error-inner"&gt;&lt;/div&gt;
                          &lt;/td&gt;
                          &lt;td&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;th valign="top" style="width:0%"&gt;&lt;span class="required"&gt;*&lt;/span&gt;Course&lt;/th&gt;
                      &lt;td style="width: 0%"&gt;
                          &lt;select name="course_name" class="select-form required " style="color:#000 !important;width:200px !important"&gt;
                              &lt;option value=""&gt;Select&lt;/option&gt;
                              &lt;?php
                                  $sql = "select * from mock_course ";
                                  $res = mysqli_query($dbhandle,$sql);
                                  $numrows =mysqli_num_rows($res);
                                  echo mysql_error();
  
                                  if($numrows){
  
                                      while($obj = mysqli_fetch_object($res)){
  
                                          if($obj-&gt;status == 1){
  
                                              if($course == $obj-&gt;id){
                                                  echo '&lt;option value="'.$obj-&gt;id.'" selected&gt;'.($obj-&gt;course_name).'&lt;/option&gt;';
                                              }
                                              else{
                                                  echo '&lt;option value="'.$obj-&gt;id.'"&gt;'.($obj-&gt;course_name).'&lt;/option&gt;';   
                                              }
                                          }
                                      }
                                  }
                              ?&gt;
                          &lt;/select&gt;
                      &lt;/td&gt;
  
                      &lt;td style="width: 0%;"&gt;
                          &lt;div id="course_id-error" class="error-inner"&gt;&lt;/div&gt;
                      &lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                  &lt;/tr&gt;
  
                  &lt;tr&gt;
                      &lt;th&gt;&lt;span class="required"&gt;*&lt;/span&gt;Chapter&lt;/th&gt;
                      &lt;td&gt;&lt;input type="text" name="chapter_name" class="inp-form required" value="&lt;?php echo $chapter;?&gt;" style="color:#000 !important;"&gt;&lt;/td&gt;
                      &lt;td&gt;
                      &lt;div&gt;&lt;/div&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
  
                   &lt;tr&gt;
                      &lt;th&gt;&amp;nbsp;&lt;/th&gt;
                      &lt;td valign="top"&gt;&lt;input type="submit" name="submit_button" value="&lt;?php echo $mode=="edit"? "Update" : "Add" ?&gt;" class="form-submit" /&gt;
                      &lt;input type="reset" value="Reset" class="form-reset" /&gt;
                   &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/form&gt;
           &lt;div class="clear"&gt;&lt;/div&gt;
      &lt;/div&gt;
  </code></pre>