How to show corrosponding values of a column of a table with selected values from dropdown on textbox or label in yii2?

i am using Yii2, i have two tables and two models:
table 1: tenderprice:(id, itemname, quanity)(id is primary key) with model name=Tenderprice, table 2:tenderpricelist:id pk,singleprice, totalprice,tenderpriceid: (tenderpriceid is foreign key refers to Tenderprice) with model name: Tenderpricelist
now i want quantity when itemname is selected:

<?
$itemtenders=Tenderprice::find()->all();
 $itemlist=ArrayHelper::map($itemtenders,'id','itemname');
 echo $form->field($model, 'tenderpriceid')->dropDownList($itemlist,['prompt'=>'Select tender'])->hint('Please choose item one by one')->label('Add Items');
 ?>
 // inserting data into tenderpricelist based on the selection of table tenderprice
  <?= $form->field($model, 'singleprice')->textInput(['maxlength' => true])->hint('Please enter your price') ?>

<?= $form->field($model, 'totalprice')->textInput(['maxlength' => true]) ?>

now i want to insert data into tenderpricelist table based on the item name selected from dropdownlist…the dropdownlist fills correctly but i cannot access the value of “quantity” column when itemname is selected.
i just want when i select item name from the dropdownlist, its corresponding quanity will be shown on textbox or label and the totalprice column in my table tenderpricelist will be : totalprice
totalprice=quantity *singleprice
note: singleprice is in table tenderpricelist, while quantity is in parent table tenderprice, please help me?

You could create a new action in your controller, where you get requested Tenderprice model and its corresponding Tenderpricelist. For example:

public function actionCalculatePrice($id)
{
  $tenderpricelist = Tenderpricelist::find()->where(['tenderpriceid' => $id])->one();
  $totalprice = $tenderpricelist->tenderprice->quantity * $tenderpricelist->singleprice;
  return $totalprice;
}

Add JS code to your form to make AJAX call to the newly created controller’s action which is fired up when the dropdownList changes. Something like:

$('#dropdown-id').on('change', function(){
  $.get($(this).data('url'), {id: $(this).val()}, function(data){
    $('#totalprice-input-id').val( data)})
});

Also add URL to the controller’s action to your dropdownlist to make it work:

echo $form->field($model, 'tenderpriceid')->dropDownList($itemlist,['prompt'=>'Select tender', 'data-url' => Url::to(['yourcontroller/calculate-price']) ])->hint('Please choose item one by one')->label('Add Items');

I have not tested these pieces of code. They are provided just to make a hint how you could accomplish the result. You have to edit them to suit your IDs, URLs, etc.