I have a dependent drop down list, I found some tutorials, and done it, but I have something witch i cant fix, I have 3 menu items, they are working and you can select normally, but if you not select anything in 1 you can see everything from DB for second and third. How to make dependence between them. Frist list is from table AUTORITY and second 2 from PRODUCTS
This is view code posted in _form.php
<?php $form = ActiveForm::begin();
//drop down for autority
echo $form->field($model, 'description')->dropDownList(
ArrayHelper::map(CertAutority::find()->all(),'id','description'),
[ 'prompt'=>'Select Autority',
'onchange'=>'
$.post("/web/sslproducts/list/'.'"+$(this).val(), function(data) {
$("select#products-id_autority").html( data );
});' ] );
//drop down for certificates
echo $form->field($model, 'id_autority')->dropDownList(
ArrayHelper::map(Products::find()->all(),'id','description'),
[
'prompt'=>'Select Certificate',
'onchange'=>'
$.post("/web/sslproducts/list1/'.'"+$(this).val(), function(data) {
$("select#products-id").html( data );
});'
] );
echo $form->field($model, 'id')->dropDownList(
ArrayHelper::map(Products::find()->all(),'id','price_1'),
['prompt'=>'Select Price/Year',] );
?>
This is code for the controller part part of 2 functions for this:
public function actionList($id)
{
$countAutority = Products::find()
->where(['id_autority' => $id,'id_currency' => Yii::$app->session->get('currency.id')])
->count();
$autority = Products::find()
->where(['id_autority' => $id,'id_currency' => Yii::$app->session->get('currency.id')])
->all();
if($countAutority > 0 )
{
foreach($autority as $certificate){
echo "<option value='".$certificate->id."'>".$certificate->popis."</option>";
}
}else{
echo "<otion>-</option>";
}
}
//Controler for passing data from certificate to price
public function actionList1($id)
{
$countPrice = Products::find()
->where(['id' => $id,'id_currency' => Yii::$app->session->get('currency.id')])
->count();
$customer = Products::find()
->where(['id' => $id,'id_currency' => Yii::$app->session->get('currency.id')])
->all();
if($countPrice > 0 )
{
foreach($customer as $price){
echo "<option value='".$price->id."'>1 year (".$price->price_1. year) </option>",
"<option value='".$price->id."'>2 years (".$price->price_2." /year) </option>",
"<option value='".$price->id."'>3 years (".$price->price_3." /year) </option>";
}
}else{
echo "<otion>-</option>";
}
}
If someone can help me with condition plz.