JSFiddle - React, Tailwind, and code Playground

by Kishore Sahasranaman

HTML

<div id="form">
    <input name="harga" type="number" class="inputStyle">
</div>
<button onclick="nambahData()">add data</button>
<br>
<button onclick="ditotal()">total all</button>
<input id="total" type=number>

CSS

.inputStyle{
    display:block;
}

JavaScript

window.nambahData = function() {
        var a = document.getElementsByName("harga");
        var b = a[0].cloneNode(false);
        document.getElementById("form").appendChild(b);
    }

window.ditotal = function() {
    var totalItems = 0;
    
    for(i=document.getElementsByName("harga").length-1;i>=0;i--)
    {
        var item = document.getElementsByName("harga")[i];
        totalItems += parseFloat(item.value);
    }
    document.getElementById("total").value = totalItems;
}