Hi All,
i have encountered some issues with using listBox dynamically. what really i wanted to do is, to pre select some options from listbox and load the page. for example,
<select name="drop1" id="Select1" size="4" multiple="multiple">
<option value="1">item 1</option>
<option selected="selected" value="2" >item 2</option>
<option selected="selected" value="3" >item 3</option>
<option value="4">item 4</option>
<option value="0">All</option>
</select>
from this code i wanted to pre select item 2 and item 3 on page load. where all the items are coming from a table.
this is my code block.
<?php echo $form->listBox($model, ‘roles’, CHtml::listData(AuthItem::model()->findAllBySql(‘select name,description from auth_items where type = 2’), ‘name’, ‘description’), array(‘multiple’=>‘Select’,
'options'=>array(
[b]'rAccountant'=>array('selected'=>'selected'),
'rAdmin'=>array('selected'=>'selected')[/b]
)));
?>
i want those two options to be selected when coming from database.
i am having some difficulties on writing the code as follows,
[b]<?php echo $form->listBox($model, ‘roles’, CHtml::listData(AuthItem::model()->findAllBySql(‘select name,description from auth_items where type = 2’), ‘name’, ‘description’), array(‘multiple’=>‘Select’,
'options'=>array(
[size="4"] foreach ($ietm as $temp){
'$temp'=>array('selected'=>'selected')
echo "";
}[/size]
)));
?>[/b] where $temp is an array and will have one or two or three items. so according the items in $temp i wanted them to be selected by default.
please help me with this issue. i am newbie to YII framework and struggling with this section badly.
many thanks in advance.
waiting for a reply.