views:

99

answers:

1

I have a shopping cart script that I am trying to modify to support multiple product selection. As it is now, the customer can select a product from a single drop down menu. Now, I would like to add multiple dropdown menus (all populated with the same options).

Here is the php that outputs the dropdown menu:

if($eshopoptions['options_num']>1){
            $opt=$eshopoptions['options_num'];
            $replace.="\n".'<label for="eopt'.$theid.'"><select id="eopt'.$theid.'" name="option">';
            for($i=1;$i<=$opt;$i++){
                $option=$eshop_product['products'][$i]['option'];
                $price=$eshop_product['products'][$i]['price'];
                if($option!=''){
                    if($price!='0.00')
                        $replace.='<option value="'.$i.'">'.stripslashes(esc_attr($option)).' @ '.sprintf( _c('%1$s%2$s|1-currency symbol 2-amount','eshop'), $currsymbol, number_format($price,2)).'</option>'."\n";
                    else
                        $replace.='<option value="'.$i.'">'.stripslashes(esc_attr($option)).'</option>'."\n";
                }


            }

Is there some really simple way of getting the code to output the menu say 3 times instead of once?

A: 

Unless you really need the redundancy, you can allow users to select multiple options by adding the multiple and, optionally, size attributes to your select tag:

if($eshopoptions['options_num']>1){
        $opt=$eshopoptions['options_num'];
        $replace.="\n".'<label for="eopt'.$theid.'"><select id="eopt'.$theid.'" name="option" multiple="multiple" size="'.$opt.'">';
        for($i=1;$i<=$opt;$i++){
            $option=$eshop_product['products'][$i]['option'];
            $price=$eshop_product['products'][$i]['price'];
            if($option!=''){
                if($price!='0.00')
                    $replace.='<option value="'.$i.'">'.stripslashes(esc_attr($option)).' @ '.sprintf( _c('%1$s%2$s|1-currency symbol 2-amount','eshop'), $currsymbol, number_format($price,2)).'</option>'."\n";
                else
                    $replace.='<option value="'.$i.'">'.stripslashes(esc_attr($option)).'</option>'."\n";
            }


        }
DBruns
If you choose this solution, you may want to add instructions on how to select multiple options by holding ctrl and clicking multiple options.
DBruns