I have this code that automatic calculate's the total quantity of the two textbox.
The problem is it only works on the first row and first modal of the table when i try to click and enter values on the second row with the modal it doesnt work anymore.
sample.png

below is the code for calculation of quantity.
(Im using the numeral.js for formatting and manipulating numbers.)

<script>
        var a = 0;
        var b = 0;
        var c = 0;
        function calc(obj) {
            var d = obj.id.toString();
            if (d == 'currentstock') {
                a = Number(obj.value);
                b = Number(document.getElementById('book_qty').value);
            } else {
                a = Number(document.getElementById('currentstock').value);
                b = Number(obj.value);
            }
            c = a + b;
             var addq = numeral(c).format('0,0');
             document.getElementById('totalqty').value = addq;
        }
    </script>

When you add any element with same name again the way
if you have only set of elements then code is like

document.formname.elements['elename'].value

if you have more than one set of elements with same names

document.formname.elements['elename'][0].value
document.formname.elements['elename'][1].value