title: Auto-submitting dynamic select form
body: <p>I'm having trouble with my dynamic select forms. When the "subject" form is submitted it works perfectly, but when the "course" form is then submitted, the form seems to submit properly (localhost/page.php?subject=1&amp;course=2), but it returns the option back to <code>null</code> so it isn't working with later php that is dependent on the <code>course_id</code>. </p>
  
  <p>Header PHP:</p>
  
  <pre><code>&lt;?php
  $subject = $course = null;
  
  $conn = mysql_connect('', '', '');
  $db = mysql_select_db('',$conn);
  
  if(isset($_GET["subject"]) &amp;&amp; is_numeric($_GET["subject"]))
  {
       $subject = $_GET["subject"];
  }
  
  if(isset($_GET["course"]) &amp;&amp; is_numeric($_GET["course"]))
  {
       $country = $_GET["course"];
  }
  ?&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>&lt;script language="JavaScript"&gt;
  
  function autoSubmit()
  {
       var formObject = document.forms['theForm'];
       formObject.submit();
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>HTML Form:</p>
  
  <pre><code>&lt;form name="theForm" method="get"&gt;
      &lt;select name="subject" onChange="autoSubmit();"&gt;
          &lt;option value="null"&gt;Select a Subject...&lt;/option&gt;
  
          &lt;?php
          $sql = "SELECT DISTINCT subj_name, subj_id FROM table1 ORDER BY subj_name";
          $result = mysql_query($sql) or die ("couldn't execute query");
  
          while($row = mysql_fetch_array($result))
          {
              echo ("&lt;option value=\"$row[subj_id]\" " . 
                   ($subject == $row["subj_id"] ? " selected" : "") . "&gt;$row[subj_name]&lt;/option&gt;");        
          }
          ?&gt;          
      &lt;/select&gt;
  
  &lt;?php
  if($subject != null &amp;&amp; is_numeric($subject))
  {
  ?&gt;
  
      &lt;select name="course" onChange="autoSubmit();"&gt;        
          &lt;option value="null"&gt;Select a Course...&lt;/option&gt;
  
          &lt;?php
          $sql = "SELECT DISTINCT course_id, course_name, subj_id FROM table1 WHERE subj_id = $subject";
          $result = mysql_query($sql);
  
          while($row = mysql_fetch_array($result))
          {
              echo ("&lt;option value=\"$row[course_id]\" " . 
                       ($course == $row["course_id"] ? " selected" : "") . "&gt;$row[course_name]&lt;/option&gt;");        
          }
          ?&gt;          
      &lt;/select&gt;
  
  &lt;?php
  }
  ?&gt;
  &lt;/form&gt;
  </code></pre>