I finally got it here is my view:
<div class="row">
<?php echo $form->labelEx($account, 'AccountTypeName'); ?>
<?php
echo CHtml::dropDownList('AccountTypeName', '', array(1 => 'Administrator', 2 => 'Manager', 3 => 'Business', 4 => 'Finance', 5 => 'Customer Support'), array(
'prompt' => '',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('loadcities'),
'update' => '#AccountGroup',
'data' => array('AccountTypeName' => 'js:this.value'),
)));
?>
<?php echo $form->error($account, 'AccountTypeName'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($account, 'AccountGroup'); ?>
<?php
echo CHtml::dropDownList('AccountGroup', '', array(), array('prompt' => ''));
?>
<?php echo $form->error($account, 'AccountGroup'); ?>
</div>
And my Controller:
public function actionLoadcities()
{
$data= RefAccountgroup::model()->findAll('AccountTypeID=:AccountTypeID',
array(':AccountTypeID'=>(int) $_POST['AccountTypeName']));
$data=CHtml::listData($data,'AccountGroupID','AccountGroupName');
echo "<option value=''></option>";
foreach($data as $value=>$city_name)
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($city_name),true);
}
It generates the second dropdown, but now my problem is I cant save the data inside my Chtml::dropdownlist, using function savedata(){
$connectionString[0] = Yii::app()->params[‘dbhandler’];
$dbhandler = new DBHandler($connectionString[0]);
$dbhandler->open();
$dbhandler->prepare(INSERT INTO data VALUES($this->AccountTypeName, $this->AccountGroup));
$dbhandler->execute();
}