I have the following active drop down list
<?php
echo CHtml::activeDropDownList($project, 'city', CHtml::listData(City::model()->findAll(), 'id', 'name'), array('class'=>'st-form', 'onchange' => 'getLocationByCity(this)'));
?>
I want to add selected option to the 10th value in the drop down list when the list is being created, how do I do it.
Thanks.
The drop down list automatically selects the option corresponding to the value of the specified attribute of the specified model. In this case, the option with value equal to $project->city is preselected.
So if you want to control which option that is, simply do
$project->city = $valueOfThatOption;
before calling activeDropDownList.
It doesn't (and shouldn't) matter if that option is 1st, 10th, or anything else.
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