hi i am using codeigniter , i want to add a multi select box to my page , 
i saw the codeigniter user guide example , but what it is doing is set the values in multi select .
like this
$options = array(
                  'small'  => 'Small Shirt',
                  'med'    => 'Medium Shirt',
                  'large'   => 'Large Shirt',
                  'xlarge' => 'Extra Large Shirt',
                );
$shirts_on_sale = array('small', 'large');
echo form_dropdown('shirts', $options, $shirts_on_sale);
in this multi select box created like this
<select name="shirts" multiple="multiple">
<option value="small" selected="selected">Small Shirt</option>
<option value="med">Medium Shirt</option>
<option value="large" selected="selected">Large Shirt</option>
<option value="xlarge">Extra Large Shirt</option>
</select>
it have to give the options to be selected in  $shirts_on_sale array , but in my case i want to create a multi select but dont want selected options  i tried to pass an empty array . but it is not working 
like this
$array = array();
echo form_dropdown('shirts', $substore_details, $array); 
how to create a multi select with no selected items . please help..............
You should use the form_multiselect() helper.
$options = array(
                  'small'  => 'Small Shirt',
                  'med'    => 'Medium Shirt',
                  'large'   => 'Large Shirt',
                  'xlarge' => 'Extra Large Shirt',
                );
echo form_multiselect('shirts', $options);
                        The only thing that comes to my mind is using an array with more than one empty element:
$options = array(
                  'small'  => 'Small Shirt',
                  'med'    => 'Medium Shirt',
                  'large'   => 'Large Shirt',
                  'xlarge' => 'Extra Large Shirt',
                );
$array = array('','');
echo form_dropdown('shirts',$options, $array);
This code works, though not the most elegant out there.
This is even better, didn't remember it at first!
echo form_multiselect('shirts',$options,'','');
Output:
<select name="shirts" multiple="multiple">
<option value="small">Small Shirt</option>
<option value="med">Medium Shirt</option>
<option value="large">Large Shirt</option>
<option value="xlarge">Extra Large Shirt</option>
</select>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With