Dependency Dropdown Country to State

Hi friends,

I am completely new to yii… Currently am working on a project and in that i want dependent dropdowns… I have 2 tables tbl_country, tbl_states…

_form.php

      <div class="row">


            <?php echo                   CHtml::dropDownList('country','',CHtml::listData(Country::model()->findAll(array('order'=>'countryname ASC')),'country_id','countryname'),array('prompt'=>'Select', 'id'=>'countryid',


    'ajax' => array(


    'type'=>'POST',


    'url'=>CController::createUrl('dynamicstates'),


    'update'=>'#stateid',


    'data'=>'js:$(this).serialize()',


    


    ))); ?>


    


    </div>





    <?php echo CHtml::dropDownList('state','',array(),array('prompt'=>'Select','id'=>'stateid')); ?>

controller.php

public function actionDynamicstates()

    {


            


            


            $data=Country::model()->findAll('country_id=:countryid', 


            array(':countryid'=>(int) $_POST['countryid']));


           


            


                              


            echo CHtml::tag('option', array('value' => 0), CHtml::encode('Select'), true); // for select





    	 $data=CHtml::listData($data,'state_id','statename');


              foreach($data as $value=>$name)


              {


                      echo CHtml::tag('option',


                                             array('value'=>$value),CHtml::encode($name),true);


              }


    }

Please help me to find the solution…

Thanks…

Worst forum nobody replied f**k

www.yiiframework.com/wiki/24/

follow the steps.and check your code




'update'=>'#stateid',

<?php echo CHtml::dropDownList('state','',array(),array('prompt'=>'Select','id'=>'stateid')); ?>



instead of this use following lines


'update'=>'#stateid',

<?php echo CHtml::dropDownList('stateid','',array()); ?>



before starting new thread please cheak all related topic.

see this one

http://www.yiiframework.com/forum/index.php/topic/32673-chosing-city-name-from-state-name/

@hemc

thanx for your answer