简体   繁体   中英

Calculate values of multiple input fields that are added by javascript codee and display for every row in Javascript

I want to calculate result for each row, I used javascript that add multiple rows, and I want calculation on every row.

 function sub() { var txtFirstNumberValue = document.getElementById('AB[]').value; var txtSecondNumberValue = document.getElementById('RAB').value; var resultMul = parseInt(txtFirstNumberValue) * parseInt(txtSecondNumberValue); var textthired = document.getElementById('RQP').value; var result = parseInt(textthired) + parseInt(resultMul); if (!isNaN(result)) { document.getElementById('TA[]').value = result; } } 
 <input type="number" name="AB[]" onkeyup="sub();" id="AB[]" min="5" max="1000" required> <input type="text" name="TA[]" id="TA[]" readonly> <input type="text" name="RQP" value="1500" readonly onkeyup="sub();" id="RQP"> <input type="text" name="RAB" value="50" readonly onkeyup="sub();" id="RAB"> 

  1. First of all last two fields are readonly so keyup function will not work.
  2. Second you add value only when there is any entry in the field by checking entered value as greater than 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM