I have two tables location and department and dropdowns for them respectively , I want when i select location from 1st dropdown then it shows the related departments for that location in 2nd dropdown. I saw a code online for AJAX but i don’t know ajax much and having difficulty understanding the code.
Here is my view
<?= $form->field($model, 'deptloc')->dropDownList(
ArrayHelper::map(\app\models\Location::find()->all(), 'loc', 'loc'), // Flat array ('id'=>'label')
['prompt' => 'Select Location',
'onchange'=>'
$.get( "'.Url::toRoute('/category/subcats').'", { id: $(this).val() } )
.done(function( data ) {
$( "#'.Html::getInputId($model, 'deptname').'" ).html( data );
}
);
','class' => 'form-control'
]
)
?>
<?= $form->field($model, 'deptid')->dropDownList(
ArrayHelper::map(\app\models\Department::find()->all(), 'deptid', 'deptname'), // Flat array ('id'=>'label')
['prompt' => 'select','class' => 'form-control']
)
?>
What is Url route in this? what url should i pass there?
Please Help, and also do i have to make changes to other files as well? or only in view.