I have six fields which are editable in my Yii2 form widget. What i want to do is once i input integer values into editable fields calculate "Green leaf net weight" automatically based on the given input. my coding are work perfectly. But the problem is if i change already input value in the fields it'll not update the the "Green leaf net weight" read only field.
$(document).ready(function(){
var A = $('#A');
var B = $('#B');
var C = $('#C');
var D = $('#D');
var E = $('#E');
E.change(function(e){
var result = ((A.val() - B.val()) * C.val())/100;
var result2 = ((A.val() - B.val()) * D.val()) / 100;
var final = ((A.val() - B.val()) - result - result2) - E.val();
Math.round(final);
$('#F').val(final);
})
});
my form widget coding (updated code)
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'Gross_weight',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput(['id' => 'A', **'class' => 'factors'** ]) ?>
<div class="panel panel-primary" style="padding: 10px;">
<div style="text-align: center; color: #008000;"><b>Deductions</b></div>
<?= $form->field($model, 'Bags_count',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput() ?>
<?= $form->field($model, 'Bags_weight',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput(['id' => 'B', **'class' => 'factors'** ]) ?>
<?= $form->field($model, 'Course_leaf',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput(['id' => 'C', **'class' => 'factors'**]) ?>
<?= $form->field($model, 'Water',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput(['id' => 'D', **'class' => 'factors'**]) ?>
<?= $form->field($model, 'Boiled_leaf',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput(['id' => 'E',**'class' => 'factors'**]) ?>
</div>
<?= $form->field($model, 'Greanleaf_net_weight',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput(['disabled' => 'disabled', 'id' => 'F']) ?>
Thanks for everyone.

E.change(function(e){ ... }).change()