So i have three tables that’s related with each other:
Fakultas
Id | nama
Jurusan
Id | fakultas_id | nama
Prodi
Id | jurusan_id | nama
My problem is, when i changed fakultas after everything was filled, it didn’t update dropdown prodi, only jurusan. So, how to update two dropdown fields?
5755
5756
5754
This’s my codes
[size="5"]view[/size]
<div class="createform">
<div class="createform-1">
<?php echo $form->labelEx($profile,'fakultas_id'); ?>
<?php echo $form->dropDownList(
$profile,
'fakultas_id',
CHtml::listData(
Fakultas::model()->findAll(),
'id',
'nama'
),
array(
'class'=>'span2',
'prompt'=>'-- fakultas',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('selectjur', array('type'=>'pengaju')),
'update'=>'#'.CHtml::activeId($profile,'jurusan_id'),
'beforeSend'=>'function() {
$("#User_jurusan_id").find("option").remove();
$("#User_prodi_id").find("option").remove();
}',
)
)
); ?>
</div>
<div class="createform-1">
<?php echo $form->labelEx($profile,'jurusan_id'); ?>
<?php echo $form->dropDownList(
$profile,
'jurusan_id',
(!$model->isNewRecord) ? $model->jurusanList() :array(),
array(
'class'=>'span2',
'prompt'=>'--',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('selectprodi', array('type'=>'pengaju')),
'update'=>'#'.CHtml::activeId($profile,'prodi_id'),
'beforeSend'=>'function() {
$("#User_prodi_id").find("option").remove();
}',
) // -- ajax --
) // -- array --
); ?>
</div>
<div class="createform-1">
<?php echo $form->labelEx($profile,'prodi_id'); ?>
<?php echo $form->dropDownList(
$profile,
'prodi_id',
(!$model->isNewRecord) ? $model->prodiList() :array(),
array(
'class'=>'span2',
'prompt'=>'--',
)
); ?>
</div>
</div>
[size="5"]Controller[/size]
public function actionSelectjur()
{
$type = $_GET['type'];
if($type == 'pengaju'){
$id_fak = $_POST['Ppengaju']['fakultas_id'];
}elseif($type == 'penilai') {
$id_fak = $_POST['Ppenilai']['fakultas_id'];
}elseif($type == 'search') {
$id_fak = $_POST['User']['fakultas_id'];
}
$list = Jurusan::model()->findAll('fakultas_id = :id_fak', array(':id_fak'=>$id_fak));
$list = CHtml::listData($list,'id','nama');
//echo CHtml::tag('option',array('value'=>''),'-- pilih jurusan --', true);
echo CHtml::tag('option',array('value'=>''),'-- pilih', true);
foreach($list as $value=>$nama){
echo CHtml::tag('option',array('value'=>$value),CHtml::encode($nama), true);
}
}
public function actionSelectprodi()
{
$type = $_GET['type'];
if($type == 'pengaju'){
$id_jur = $_POST['Ppengaju']['jurusan_id'];
}elseif($type == 'penilai') {
$id_jur = $_POST['Ppenilai']['jurusan_id'];
}elseif($type == 'search') {
$id_jur = $_POST['User']['jurusan_id'];
}
$list = Prodi::model()->findAll('jurusan_id = :id_jur', array(':id_jur'=>$id_jur));
$list = CHtml::listData($list,'id','nama');
//echo CHtml::tag('option',array('value'=>''),'-- pilih program studi --', true);
echo CHtml::tag('option',array('value'=>''),'-- pilih', true);
foreach($list as $value=>$nama){
echo CHtml::tag('option',array('value'=>$value),CHtml::encode($nama), true);
}
}