I need help implementing a specific formula in JavaScript that involves dealing with 5 input fields.
Below is the HTML code (apologies for the language, it is in a different locale):
<div class="row" style="padding:10px 12px;">
<div class="row">
<div style="display:flex; justify-content:space-between; flex-wrap:wrap;">
<label class="control-label col-lg-6 col-md-6 col-sm-6" for="K">Shkolla e Mesme:</label>
<div class="controls">
<select name="K" class="span3 col-lg-6 col-md-6 col-sm-6 form-control1" id="K">
// Option values go here
</select>
</div>
</div>
</div>
// Additional input field elements go here
</div>
The formula that needs to be applied is:
{[26 x Field1 + 20 x Field2 + Field3 + Field4)] x 1.4 + 17 x (Field5 x 1.3 + Field6 x 1.2)} x 5
There is a sample code below that might be helpful, but adjustments are needed:
Qty1 : <input onblur="findTotal()" type="text" name="qty" id="qty2"/><br>
// Additional input fields go here
Total : <input type="text" name="total" id="total"/>
<script type="text/javascript">
function findTotal(){
var arr = document.getElementsByName('qty');
var tot=0;
for(var i=0;i<arr.length;i++){
if(parseInt(arr[i].value))
tot += parseInt(arr[i].value);
}
document.getElementById('total').value = tot;
}
</script>
Any guidance or assistance is greatly appreciated. Thank you.