I am trying dynamic sum with JavaScript in my Laravel application. It is working fine when there is one row. But if I make a for each loop, how can I get the sum for each row?
Here is my form:
@foreach($users as $user)
<div class="form-group">
<input id="item1" type="number" class="prc form-control" name="item1[]">
</div>
<div class="form-group">
<input id="item2" type="number" class="prc form-control" name="item2[]">
</div>
<output id="result" class="form-group"></output>
@endforeach
My JavaScript code is
$('.form-group').on('input', '.prc', function(){
let totalSum = 0;
$('.form-group .prc').each(function(){
const inputVal = $(this).val();
if($.isNumeric(inputVal)){
totalSum += parseFloat(inputVal);
}
});
$('#result').text(totalSum);
});
I am getting the result in the first row only. How can I get values row by row?

idandnamelike add extraforeachkey and add this key withidandname