JSFiddle - React, Tailwind, and code Playground

by dauruk0512

HTML

<input name="total[]" value="500" onchange="hitung();" >
    <input name="total[]" value="300" onchange="hitung();" >
        <input name="total[]" value="200" onchange="hitung();" >
            
            <input type="final" type="text" class="total">
            
            <button type="button" id="btn">get total</button>

JavaScript

function hitung() {
    
var total = 0;
    $('input[name^="total"]').each(function() {
          var tot = Number($(this).val());
          total += tot;
    });
    
$(".total").val(total);  
}