Retrieving Other Attributes Of Model In Dropdown List With Chtml::listdata

Hi all,

I am using in my form a dropdown list with CHtml::listData in the following way:-





<div class="row">

 <?php echo $form->labelEx($model,'des_res_id'); ?>

 <?php echo $form->dropDownList($model, 'des_res_id',

 CHtml::listData($data, 'id','ClientId'), array('empty'=>'None','id'=>'res')); ?>				

 <?php echo $form->error($model,'des_res_id'); ?><div  id='info' style="display: inline;"></div>

</div>




In the above code, I am using ‘id’ as the value and ‘ClientId’ as text for the dropDownList and $data is the list of model objects from which these values come. Once I select the value, I would like to display in the div (id=‘info’) some text which is actually another attribute (name) of the model object and this information is available in $data. I can write a function in the controller which can be called to display this info in the required div by using jquery and $("#info").html. But I guess there must be a shorter way of doing since this information is readily available in the list of model objects for the dropdownlist.

Can anyone tell me how to do it?

Thanks

Did you ever figure out how to do this? I am also attempting to do something similar, i.e. include an extra attribute in the option that would be available client side. I want to end up with options in a dropdown list whose markup looks something like this




...

<option value="12" extra="code">String</option>

...



This thread answered my question!

http://www.yiiframework.com/forum/index.php/topic/9693-cactiveform-dropdownlist-selectedselected/page__view__findpost__p__134776

Hi, did you still have the solution? I can’t found the thread from your link. Thanks

Try this link, CActiveForm->dropDownList selected="selected" - #8 by realitylord