Difference between #9 and #10 of
Creating a dependent dropdown

Revision #10 has been created by Maurizio Domba Cerin on Feb 6, 2012, 8:38:16 AM with the memo:

styled a bit, removed unnecesary line and added sub-headers
« previous (#9) next (#11) »

Changes

Title unchanged

Creating a dependent dropdown

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

AJAX

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 AJAX 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.


```php
public function actionDynamiccities()
{
[...]
83 2
92 followers
Viewed: 417 176 times
Version: 1.1
Category: Tutorials
Written by: dalip
Last updated by: Paul_Kish
Created on: Mar 23, 2009
Last updated: 10 years ago
Update Article

Revisions

View all history