JSFiddle - React, Tailwind, and code Playground

by Nenad Novakovic

HTML

<input type="text" name="quantity" class="quantity" value="1" data-price="4" />

<input type="text" name="quantity" class="quantity" value="34" data-price="5" />

<input type="text" name="quantity" class="quantity" value="12" data-price="8" />

<input name="total" id="total" val="" />

JavaScript

var value = 0, price = 0;

$('.quantity').each(function () {
    var val = value += Number($(this).val()),
        data = price += $(this).data('price'),
        total = val * data;
    
    $('#total').val(total);
});