title: Create checkbox to select all options in a selection box
body: <p>My 2nd PHP assignment requires that I create a selection box with a range of years, a second selection box with the 12 months and then a checkbox beneath which the user can select if they want to choose an entire year. I've created the checkbox but I do not understand how to make it select all the months. I've spent over 2 hours trying to find a solution and I apologize for not having a code attempt for this particular part of my assignment. I honestly don't know where to begin.  My understanding of PHP is so narrow right now. I don't even know exactly how to properly word a google search for this problem. Every search leads me to instructions on how to create a selection box that allows for multiple selections. The only sites I've found on creating a "select all" option shows it done with JS. I must do this in PHP.</p>
  
  <p>I should add that I'm only allowed to use PHP and HTML with a bit of CSS styling with this assignment. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;title&gt;Calendar&lt;/title&gt;
      &lt;!--    &lt;link rel="stylesheet" type="text/css" href="quote.css"&gt;--&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;section&gt;
      &lt;form id="yearForm" name="yearForm" method="post" action=""&gt;
          &lt;label for="select_year"&gt;Select the year: &lt;/label&gt;
          &lt;?php
          // Sets the default year to be the current year.
          $date = new DateTime();
  //        $current_year = date('Y');
          $current_year = $date-&gt;format('Y');
          // Year to start available options.
          $earliest_year = ($current_year - 5);
          // Set your latest year you want in the range.
          $latest_year = 2050;
  
          echo '&lt;select&gt;';
          // Loops over each int[year] from current year, back to the $earliest_year [1950]
          foreach ( range( $earliest_year, $latest_year ) as $i ) {
              // Echos the option with the next year in range.
              echo '&lt;option value="'.$i.'" '.($i == $current_year ? ' selected="selected"' : '').'&gt;'.$i.'&lt;/option&gt;';
          }
          echo '&lt;/select&gt;';
          ?&gt;
      &lt;/form&gt;
          &lt;br /&gt;
          &lt;br /&gt;
      &lt;form id="monthForm" name="monthForm" method="post" action=""&gt;
          &lt;label for="month"&gt;Select the month: &lt;/label&gt;
  &lt;!--        &lt;input type=hidden id="month" name=month&gt;--&gt;
                          &lt;select id="month" name="month" &gt;
                              &lt;option value='01'&gt;January&lt;/option&gt;
                              &lt;option value='02'&gt;February&lt;/option&gt;
                              &lt;option value='03'&gt;March&lt;/option&gt;
                              &lt;option value='04'&gt;April&lt;/option&gt;
                              &lt;option value='05'&gt;May&lt;/option&gt;
                              &lt;option value='06'&gt;June&lt;/option&gt;
                              &lt;option value='07'&gt;July&lt;/option&gt;
                              &lt;option value='08'&gt;August&lt;/option&gt;
                              &lt;option value='09'&gt;September&lt;/option&gt;
                              &lt;option value='10'&gt;October&lt;/option&gt;
                              &lt;option value='11'&gt;November&lt;/option&gt;
                              &lt;option value='12'&gt;December&lt;/option&gt;
                          &lt;/select&gt;
                          &lt;br /&gt;
                          &lt;br /&gt;
          &lt;label for="whole_year"&gt;Show whole year: &lt;/label&gt;
          &lt;input type="checkbox" id="whole_year" name="whole_year" &gt;
          &lt;br /&gt;
          &lt;br /&gt;
          &lt;input type="submit" class=inline name="submitButton" id="submitButton" value="Submit" /&gt;
      &lt;/form&gt;
  &lt;/section&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>