Creating a dependent dropdown

Comparing #6 with #7

Revision #7 was created by Michel Kogan Michel Kogan on Sep 12, 2011, 7:27:42 PM.

change ajax to AJAX

Content

Often you'll need a form with two dropdowns, and one dropdown's values will be dependent on the value of the other dropdown. Using Yii's built-in ajaxAJAX functionality you can create such a dropdown. Below will be demonstrated how you can achieve this.

First the view with the form. We'll show a form that shows countries and dependent of the country selected will show cities.

```php
echo CHtml::dropDownList('country_id','', array(1=>'USA',2=>'France',3=>'Japan'),
[...]