JSFiddle - React, Tailwind, and code Playground

by Santosh J

HTML

<input name="subtotal" id="subtotal" type="number" maxlength="20" min="0" placeholder="00.00" onchange="vatCalculation();" />

<input name="vat" id="vat" type="text" maxlength="20" min="0" placeholder="00.00" readonly="true" />

<input name="total" id="total" type="text" maxlength="20" min="0" placeholder="00.00" readonly="true" />

<script>
    function vatCalculation() {
var subtotal = document.getElementById('subtotal').value;
var vat = parseFloat(parseFloat(subtotal) * parseFloat(0.2)).toFixed(2);
var total = parseFloat(parseFloat(subtotal) + parseFloat(vat)).toFixed(2);

document.getElementById('vat').value = vat;
document.getElementById('total').value = Math.round(total).toFixed(2);
}
    </script>