title: Populate dropdown based on checkbox
body: <p>I have a form that contains a checkbox and a dropdown list. I use PHP to populate the dropdown list from two MySQL tables. Which table I use depends on whether the checkbox was checked or not. But, as you can see from my code sample, I can only populate that dropdown list after I submit the form. I want to be able to keep clicking on the checkbox and keep re-populating the dropdown list without having to submit the form. I am still new to this, so, please, give me as simple a solution as possible.</p>
  <p>PS. I have a small bug in the code that doesn't keep the checkbox checked/unchecked after I submit the form. Working on fixing it.</p>
  <p>Thank you</p>
  <hr />
  <pre><code>&lt;?php
  $Prc_Earn = 'Prc';
  if (isset($_POST['submitBtn']))
    {
      if (isset($_POST['chkbox']))
        {
          $sql = 'select distinct Symbol from price_history.quarterly_earnings_history';
          $Prc_Earn = 'Earn';
        }
      else
        {
          $sql = 'select distinct Symbol from price_history.stock_symbol_list';
          $Prc_Earn = 'Prc';
        }
      }
  // Connect to the database
  include ('../Connections/mysql_connect.php');
  if ($dbcon)
    {
  ?&gt;
      &lt;form method='post'&gt;
          &lt;label for=''&gt;Earnings / Prices&lt;/label&gt;
          &lt;input type='checkbox' name='chkbox' id='chkbox' &lt;?php if ($Prc_Earn == 'Prc') { echo &quot;checked&quot;; };?&gt;&gt;&lt;br&gt;&lt;br&gt;
  
          &lt;label for='symbol'&gt;Stock Symbol:&lt;/label&gt;
          &lt;select name = 'symbol' id='symbol'&gt;
  &lt;?php
          $result = mysqli_query($dbcon, $sql);
          if (mysqli_num_rows($result) &gt; 0)
            {
              while($row = mysqli_fetch_array($result))
                { echo '&lt;option value=&quot;' . $row['Symbol'] . '&quot;&gt;' . $row['Symbol'] . '&lt;/option&gt;'; }
            }
  ?&gt;
          &lt;/select&gt;&lt;br&gt;&lt;br&gt;
          &lt;button class='button' type='submit' name='submitBtn' id='submitBtn'&gt;View Data&lt;/button&gt;&lt;br&gt;&lt;br&gt;
      &lt;/form&gt;
  &lt;?php
    }
  ?&gt;
  </code></pre>