Difference between #4 and #15 of
Creating a dependent dropdown

Changes

Title unchanged

Creating a dependent dropdown

Category unchanged

Tutorials

Yii version unchanged

Tags changed

AJAX, drop down list

Content changed

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. 

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

```php
[...]
The first dropdown is filled with several value/name pairs of countries. Whenever it is changed an ajax request will be done to the 'dynamiccities' action of the current controller. The result of that request (output of the 'dynamiccities' action) will be placed in the second dropdown with id is #city_id.

Next is tThe controller action, i
 
---------------------
 
I
t will have to output the html to fill the second dropdownlist. Furthermore it will do that dependent on the the value of the first dropdown.
[...]
in the filters() Method. This will disable all access controls for the controller. You should always re-enable it after testing.

###Related Links [Chinese version](http://dreamneverfall.cn/node/80-------------
 
[Persian version](http://shgn.ir/%D8%A7%DB%8C%D8%AC%D8%A7%D8%AF-%D9%84%DB%8C%D8%B3%D8%AA-%D9%87%D8%A7%DB%8C-%D9%88%D8%A7%D8%A8%D8%B3%D8%AA%D9%87-%D8%A8%D9%87-%D9%87%D9%85-%D8%AF%D8%B1-yii/ "Persian Version"
)
83 2
92 followers
Viewed: 416 858 times
Version: 1.1
Category: Tutorials
Written by: dalip
Last updated by: Paul_Kish
Created on: Mar 23, 2009
Last updated: 9 years ago
Update Article

Revisions

View all history