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">
<?php echo $form->labelEx($model,'State'); ?>
<?php
$list=CHtml::listData(tblcitylist::model()->findAll(),'state','state');
echo CHtml::activeDropDownList('prjid','', $list,
array(
'empty'=>'Please Select',
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('Registrationd/dynamiccity'), //url to call.
'update'=>'#prjid', //selector to update
'data'=>'js:$(this).serialize()',
)));
?>
<?php echo $form->error($model,'State'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'City'); ?>
<?php
//empty since it will be filled by the other dropdown
echo CHtml::activeDropDownList('prjid','', array(),array('empty'=>'Select','style'=>'width:120px;'));
//echo CHtml::activeDropDownList($model,'city_id', array(),array('prjid'=>'city_id'));
// echo CHtml::activeHiddenField($model,'city_id');
?>
<?php echo $form->error($model,'City'); ?>
</div>
and then in controller.php
public function actiondynamiccity()
{
$data=Lab::model()->findAllBySql('select city_name from tblcitylist where state='.$_POST['state']);
$data=CHtml::listData($data,'prjid','city_name');
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}