0

When i add extra atrribute to options in CHtml::dropDownList(), i am not able to set options selected.

Without adding extra atrribute to CHtml::dropDownList(), i am able to get an option selected and the code for this is

echo CHtml::dropDownList("rating[$i]", '', CHtml::listData(Rating::model()->findAll($criteria), 'id', 'Description'), array('prompt' => 'Select a rating', 'options' => array($question->rating_id => array('selected' => TRUE)), 'class' => 'input-xlarge ddc hrq'));

But when i add extra atrribute, selected option not work, modified code is

 echo CHtml::dropDownList("rating[$i]", '', CHtml::listData(Rating::model()->findAll($criteria), 'id', 'Description'), array('prompt' => 'Select a rating', 'options' => array($question->rating_id => array('selected' => TRUE), '1' => array('number' => 5), '2' => array('number' => 4), '3' => array('number' => 3), '4' => array('number' => 2), '5' => array('number' => 1), '16' => array('number' => 0)), 'class' => 'input-xlarge ddc hrq'));

Please help me with this. Thanks in advance :)

Vikky
  • 43
  • 1
  • 7
  • What do you want get with ` '1' => array('number' => 5), '2' => array('number' => 4), '3' => array('number' => 3), '4' => array('number' => 2), '5' => array('number' => 1), '16' => array('number' => 0) `..? this don't seems attribute but somethings related to the valeu of the options .. – ScaisEdge Dec 31 '15 at 07:36
  • What do you mean by "selected option not work" ? Also try selected="selected" instead of selected="true" – crafter Dec 31 '15 at 08:53
  • It gives me drop down like `` i need number attribute to perform some ajax operation, thats why it is there – Vikky Dec 31 '15 at 09:32
  • "selected option not work" means options in the drop down not getting selected, which is stored in db – Vikky Dec 31 '15 at 09:35

0 Answers0