_form.php
i does not display the first country select and his contry only state display
this file in all country state and city display plz give me code
<div class="row">
<tr>
<td>
<?php echo $form->labelEx($model,'country'); ?>
</td>
<td>
<?php
$CountryArray = CHtml::listData(country::model()->findAll(),'cid','country');
echo $form->DropDownList($model,'cid',$CountryArray,array('prompt'=>'--select--'),
array(
'ajax' => array(
'onchange' => 'getState(this.value)',
'update'=>'#'.CHtml::activeId($model,'sid'))));
?>
<script>function getState(val)
{
$.ajax(
{
type :'POST', //request type
url : '<?php echo CController::createUrl('controller/dynamicState')?>',
success : function(data)
{
$('#sid').html(data);
}
};
}
</script>
</td>
</tr>
<?php echo $form->error($model,'cid'); ?>
</div>
<div class="row">
<tr>
<td>
<?php echo $form->labelEx($model,'state'); ?>
</td>
<td>
<?php echo $form->DropDownList($model,'sid',
CHtml::listData(state::model()->findAll(), 'sid', 'state'),array('prompt'=>'--select--'),
array(
'ajax' => array(
'onchange' => 'getCity(this.value)',
'update'=>'#'.CHtml::activeId($model,'ctid'))));
?>
<script>function getCity(val)
{
$.ajax(
{
type :'POST', //request type
url : '<?php echo CController::createUrl('controller/dynamicCity')?>',
success : function(data)
{
$('#ctid').html(data);
}
};
}
</script>
<?php echo $form->error($model,'sid'); ?>
</td>
</tr>
</div>
<div class="row">
<tr>
<td>
<?php echo $form->labelEx($model,'city'); ?>
</td>
<td>
<?php echo $form->DropDownList($model,'ctid',
CHtml::listData(city::model()->findAll(), 'ctid', 'city'),array('prompt'=>'--Select--') ); ?>
<?php echo $form->error($model,'ctid'); ?>
</td>
</tr>
</div>
statecontrollers.php
public function actionDynamicState()
{
while($row=mysql_fetch_array($data))
{
$cid = $_POST['state']['cid'];
$data=state::model()->findAll('cid=:cid',
array(':cid'=>(int) $_POST['cid']));
$data=CHtml::listData($data,'sid','state');
foreach($data as $value=>$state)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($state),true);
}
}
}