There was such a task: when selecting an item from the dropdownlist, the id value needs to be passed in two actions, but onchange only executes the first request. Request Code:

<?= $form->field($model, 'ID_region')->dropDownList($arrReg,[ 'prompt'=>'Область', 'onchange'=>'$.post("/enrollee/area/lists?ID='.'"+$(this).val(),function (data){ $("select#enrollee-id_area").html(data); });' and '$.post("/enrollee/city/lists?ID='.'"+$(this).val(),function (data){ $("select#enrollee-id_city").html(data); });' , ]) ?> 
  • I propose to use two models in one action. There will be easier and more understandable. - Abdumalik Nabiev
  • And onchange cannot fulfill two requests? - razor26

1 answer 1

Solved the problem like this:

  <?= $form->field($model, 'ID_region')->dropDownList($arrReg,[ 'prompt'=>'Область', 'onchange'=>'$.post("/enrollee/area/lists?ID='.'"+$(this).val(),function (data){ $("select#enrollee-id_area").html(data); }); $.post("/enrollee/city/lists?ID='.'"+$(this).val(),function (data){ $("select#enrollee-id_city").html(data); });', ]) ?>