Web Development

Default selected value in a dropdownlist in Yii

A views level solution, is using the “options” entry in the array of htmloptions, I read it in the CHtml Dropdownlist (DropDownList Detail) documentation, but I applied it for an ActiveForm Dropdownlist. So in this example, if the reader wants the item with key value “2” to be selected by default, she/he should use:

echo dropDownList($model,'product_id', array('1' => 'Monitor', '2' => 'Keyboard'), array('prompt'=>'--select--','onchange'=>"javascript:combine_product_id();", 'id'=>'product_list', 'options'=>array(2=>array('selected'=>'selected'))



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s