dependent dropdown list

for this

i have two tables one is registaration having many columns.

and second table is citylist in which there are only three columns city_id,city_name,state name

and i want to popualte dropdown for city list by getting state name from table and insert into

first table i.e registration

this is my view.php

<div class="row">

  &lt;?php echo &#036;form-&gt;labelEx(&#036;model,'State'); ?&gt;


            &lt;?php


                    &#036;list=CHtml::listData(tblcitylist::model()-&gt;findAll(),'state','state');


                    echo CHtml::activeDropDownList('prjid','', &#036;list,


                    array(


                    'empty'=&gt;'Please Select',


                    'ajax' =&gt; array(


                    'type'=&gt;'POST', //request type


                    'url'=&gt;CController::createUrl('Registrationd/dynamiccity'), //url to call.


                    'update'=&gt;'#prjid', //selector to update


					 'data'=&gt;'js:&#036;(this).serialize()', 


        


                    ))); 


            ?&gt;


			&lt;?php echo &#036;form-&gt;error(&#036;model,'State'); ?&gt;


    &lt;/div&gt;


    &lt;div class=&quot;row&quot;&gt;


	      &lt;?php echo &#036;form-&gt;labelEx(&#036;model,'City'); ?&gt;


            &lt;?php


                    //empty since it will be filled by the other dropdown


                    echo CHtml::activeDropDownList('prjid','', array(),array('empty'=&gt;'Select','style'=&gt;'width:120px;'));                


                    //echo CHtml::activeDropDownList(&#036;model,'city_id', array(),array('prjid'=&gt;'city_id'));


               // echo CHtml::activeHiddenField(&#036;model,'city_id');             


		   ?&gt;


			&lt;?php echo &#036;form-&gt;error(&#036;model,'City'); ?&gt;


    &lt;/div&gt;

and then in controller.php

public function actiondynamiccity()

    {


            &#036;data=Lab::model()-&gt;findAllBySql('select city_name from tblcitylist where  state='.&#036;_POST['state']); 


            &#036;data=CHtml::listData(&#036;data,'prjid','city_name'); 


            foreach(&#036;data as &#036;value=&gt;&#036;name) 


            { 


                    echo CHtml::tag('option', 


                    array('value'=&gt;&#036;value),CHtml::encode(&#036;name),true); 


            } 


            


    }

use 2nd like this, give that id to it…

echo CHtml::activeDropDownList($model,‘batch_id’,$data1,array(‘prompt’=>‘Select’,‘id’=>‘batch_id’));

use another id to 2nd dropdown

‘update’=>’#batch_id

echo CHtml::activeDropDownList($model,‘city_id’, array(),array(‘id’=>‘city_id’));

and update ‘city_id’

if possible please send me modified code,

i am not getting you…

actually i am trying to populate both state and city drop down list from same table.

Hi,

don’t forget to use the code snippet tool when you insert code in your forum post, otherwise it’s not easy to read your code.

You should have a look at this if you haven’t yet, there are complete examples:

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

Hope it helps.