Dynamic Loading Data In Selection Box

Assume I have a form with 2 select box (dropdown list) named country and province. When I choose any item in country box, the correspond provinces with the selected country will be loaded automatically without reloading page. Can anyone give me any advices for this issue in yii.

Thanks in advance! :lol:

First you can create the country drop-down list and call ajax


 <?php

                echo CHtml::dropDownList('country_name', '', CHtml::listData(Country::model()->findAll('status!="2"'), 'id', 'venue_name'), array(

                    'id' => 'send_venue',

                    'prompt' => 'Select Venue',

                    'class' => 'col_165',

                    'ajax' => array(

                        'type' => 'POST',

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

                        'update' => '#county_name',

                        'data' => array('county_id' => 'js:this.value'),

                        )));

                ?>



and create the div


<div id="#county_name"></div>

then after create the Getprovince function on your controller


public function actionGetprovince($id){

                 $county_id=$_POST['county_id'];

		$data=Provinces::model()->findAll("county_id='".$county_id."' AND status='1'");

		$data=CHtml::listData($data,'id','provinces_name');

		echo "<option value=''>Select Event</option>";

		foreach($data as $value=>$event_name){

			echo CHtml::tag('option', array('value'=>$value),CHtml::encode($event_name),true);

		}

}

more reference

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

i hope it’s works…

Hi

I have two tables in my database (generate_id) name :-

  1. add_school(id,school_name,school_logo,school_address,school_phone,school_email,school_website)

  2. add_student(id,student_name,father_name,school_name,school_logo,school_address,school_phone,school_email,school_website,class_name)

i have generated crud for both.

I want data input in first model AddSchool but when i input data in AddStudent using create view it should be auto update text field i.e.,school_logo,school_address,school_phone,school_email,school_website on select dropdown list of school_name.

i have no idea please help me.

thanks in advance.