Two dropdown lists depending of only one dropdown list using Yii2

I am working with Yii2 on a project.
What I’m trying to do is in a form have two dropdown lists to load values depending of one single dropdown list.
Let me explain, I have 3 dropdown lists in my form by now

  1. class_master (id, class_name)
  2. class_arm(id, class_master_id, class_arm_name)
  3. class_subject (id, class_master_id, class_subject_name)
    What I want to do is when the user selects a ClassMaster on dropdown 1, the dropdown lists 2 and 3 load the data related to that specific ClassMaster at the same time. The condition for Dropdown lists 2 and 3 is that class_master_id = id in class_master.

ClassMaster

    public function attributeLabels()
{
    return [
        'id' => Yii::t('aca', 'ID'),
        'class_name' => Yii::t('aca', 'Class Name'),
    ];
}

ClassArm
public function attributeLabels()
{
return [
‘id’ => Yii::t(‘aca’, ‘ID’),
‘class_arm_name’ => Yii::t(‘aca’, ‘Class Arm Name’),
‘class_master_id’ => Yii::t(‘aca’, ‘Class Name’),
];
}

ClassSubject
public function attributeLabels()
{
return [
‘id’ => Yii::t(‘aca’, ‘ID’),
‘class_subject_name’ => Yii::t(‘aca’, ‘Subject Name’),
‘class_master_id’ => Yii::t(‘aca’, ‘Class Name’),
];
}

How do I make dropdownlist one on change to load dropdownlists 2 and 3 based on class_master_id = id

Thanks

Hi There,

This link may help you better ===> https://www.yiiframework.com/wiki/723/creating-a-dependent-dropdown-from-scratch-in-yii2