Answer the question
In order to leave comments, you need to log in
How to make dynamic select using PHP Yii?
There are two selects, when you select one value in the first, the values in the second should change, (example: country-> region)
After reading the Yii Framework documentation, this is what I did:
page
// первый select
<?= CHtml::dropDownList('offerDetailType', '', array(
'CONVERTIBLE_NOTE' => 'Convertible Note',
'DEBT' => 'Debt',
'EQUITY' => 'Equity'
), array(
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('startupController/instrumentType'),
'update' => '#instrumentType'
),
'empty' => 'Select Type',
'class' => 'form-control'
)); ?>
// второй select
<?= CHtml::dropDownList('instrumentType', '', array(), array('class' => 'form-control')); ?>
public function actionInstrumentType() {
switch ($_POST['offerDetailType']) {
case 'CONVERTIBLE_NOTE':
$data = array('CONVERTIBLE_NOTE' => 'Convertible Note');
break;
case 'DEBT':
$data = array('NOTE_DEBENTURE' => 'Debenture');
break;
case 'EQUITY':
$data = array(
'SHARE_COMMON' => 'Common',
'SHARE_PREFERRED' => 'Preferred'
);
break;
}
$data = CHtml::listData($data,'id','name');
foreach ($data as $value=>$name) {
echo CHtml::tag('option', array('value'=>$value),CHtml::encode($name), true);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question