title: Generate dropdown menu dynamically and change php variables on option select
body: <p>I am trying to get dropdown menu to set a value to a php variables on option selected. I can print the menu dynamically with the code below:</p>
  
  <pre><code>&lt;?php
              $option_to_preselect = $package_name;
              $ddown_options = $package_name;
              $arrlength = count($ddown_options);
  
              print '&lt;select name = "package" id = "pack_select" class="select-submit2"&gt;';
  
              for ($i=1; $i &lt; $arrlength; $i++)
              { 
                       if ($ddown_options[$i]==$option_to_preselect) 
                      { 
                          print '    &lt;option value ="' . $ddown_options[$i] . '"' . ' selected ="selected"&gt;' . $ddown_options[$i] . '&lt;/option&gt;';
                          $packageID = $i;
                          $packagePrice = $packages_price[$i];
                      }   else {
                                  print '    &lt;option value="' . $ddown_options[$i] . '"&gt;' . $ddown_options[$i] . '&lt;/option&gt;';
                          $packageID = $i;
                          $packagePrice = $packages_price[$i];
                               }
              }  
               print '&lt;/select&gt;';
  
    ?&gt;
  </code></pre>
  
  <p>Then when the user selects an option, the variables $packageID and $packagePrice should obtain the id and the amount of the selected package.</p>
  
  <p>The idea is to pass the values in a href where the href is:</p>
  
  <pre><code>href="&lt;?php echo site_url('package_purchase/'.$lang_code.'/'.$packageID.'/'.$packagePrice); ?&gt;"
  </code></pre>
  
  <p>The output of the $package_name is:</p>
  
  <pre><code>    array (size=4)
    '' =&gt; string '' (length=0)
    1 =&gt; string 'Free' (length=4)
    2 =&gt; string 'Basic' (length=5)
    3 =&gt; string 'Premium' (length=7)
  </code></pre>
  
  <p>and the result of the code looks like:</p>
  
  <pre><code>&lt;select name="package" id="pack_select" class="select-submit2"&gt;
  &lt;option value="Free"&gt;Free&lt;/option&gt;
  &lt;option value="Basic"&gt;Basic&lt;/option&gt;
  &lt;option value="Premium"&gt;Premium&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>