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:
<?php
$option_to_preselect = $package_name;
$ddown_options = $package_name;
$arrlength = count($ddown_options);
print '<select name = "package" id = "pack_select" class="select-submit2">';
for ($i=1; $i < $arrlength; $i++)
{
if ($ddown_options[$i]==$option_to_preselect)
{
print ' <option value ="' . $ddown_options[$i] . '"' . ' selected ="selected">' . $ddown_options[$i] . '</option>';
$packageID = $i;
$packagePrice = $packages_price[$i];
} else {
print ' <option value="' . $ddown_options[$i] . '">' . $ddown_options[$i] . '</option>';
$packageID = $i;
$packagePrice = $packages_price[$i];
}
}
print '</select>';
?>
Then when the user selects an option, the variables $packageID and $packagePrice should obtain the id and the amount of the selected package.
The idea is to pass the values in a href where the href is:
href="<?php echo site_url('package_purchase/'.$lang_code.'/'.$packageID.'/'.$packagePrice); ?>"
The output of the $package_name is:
array (size=4)
'' => string '' (length=0)
1 => string 'Free' (length=4)
2 => string 'Basic' (length=5)
3 => string 'Premium' (length=7)
and the result of the code looks like:
<select name="package" id="pack_select" class="select-submit2">
<option value="Free">Free</option>
<option value="Basic">Basic</option>
<option value="Premium">Premium</option>
</select>