Creating A Dependant Dropdown Without Database Tables

Hello,

I’m trying to create dependant dropdown without using database tables. And the values will be loaded in the function and returned.In the view, i have set those values in the dropdown. Now the problem is i want to make the sencond dropdown list dependant based on the the value selected in the first drop down.

Here is what i have done till now.

In my Model :

public function getDistrictList(){

	return array(


			array('key'=>'GLB', 'value'=>'Gulbarga'),


			array('key'=>'YG', 'value'=>'Yadgir'),


			array('key'=>'BNG', 'value'=>'Bangalore'),


			array('key'=>'MSR', 'value'=>'Mysore'),


			);


}


public function getTalukList(){


	return array(


			array('key'=>'BN', 'value'=>'Bangalore North'),


			array('key'=>'BS', 'value'=>'Bangalore South'),


			array('key'=>'BE', 'value'=>'Bangalore East'),


			array('key'=>'ANK', 'value'=>'Anekal'),


			array('key'=>'GLB', 'value'=>'Gulbarga'),


			array('key'=>'YG', 'value'=>'Yadgir'),


			array('key'=>'SDM', 'value'=>'Sedam'),


			array('key'=>'CHT', 'value'=>'Chittapur'),


			array('key'=>'CHN', 'value'=>'Chincholi'),


			array('key'=>'JVG', 'value'=>'Jevargi'),


			array('key'=>'MSR', 'value'=>'Mysore'),


			);


}

In my view :

<div class="row">

&lt;label for=&quot;district&quot;&gt;&lt;?php echo CHtml::encode(&#036;model-&gt;getAttributeLabel('district')); ?&gt;&lt;/label&gt;


&lt;?php &#036;list = CHtml::listData(Inquiries::model()-&gt;getDistrictList(), 'key', 'value'); ?&gt;


&lt;?php echo &#036;form-&gt;dropDownList(&#036;model, 'district', &#036;list, array('empty'=&gt;'(Select a District)')); ?&gt;


&lt;/div&gt;

<div class="row">

&lt;label for=&quot;taluq&quot;&gt;&lt;?php echo CHtml::encode(&#036;model-&gt;getAttributeLabel('taluq')); ?&gt;&lt;/label&gt;


&lt;?php &#036;list = CHtml::listData(Inquiries::model()-&gt;getTalukList(), 'key', 'value'); ?&gt;


&lt;?php echo &#036;form-&gt;dropDownList(&#036;model, 'taluq', &#036;list, array('empty'=&gt;'(Select a Taluk)')); ?&gt;


&lt;/div&gt;

Please help me.

This will help you

http://www.yiiframework.com/wiki/429/an-easy-solution-for-dependent-dropdownlist-using-ajax/

Or this

http://www.yiiframework.com/wiki/24/

[color="#006400"]NOTE: moved to proper section (General Discussion for Yii 1.1.x instead of the book section)[/color]