JSFiddle - React, Tailwind, and code Playground

by Daedalus

HTML

<form id="rtfCalc" oninput="updateOutput()">
    <input name="sale_amount" type="number" value="0" />
    <output name="transfer_fee" for="sale amount"></output>
</form>

JavaScript

function updateOutput() {
    var form = document.getElementById("rtfCalc");
    var out = form.elements["transfer_fee"];
    var amount = parseInt(form.elements["sale_amount"].value);
    
    function normalrtfCalc(amount) {
        
        if (amount <= 150000) {
            out.value = Math.ceil(amount / 500) * 2;
            
        } else if (amount <= 350000) {
            if ((amount - 150000) <= 50000) {
                out.value = 600 + (Math.ceil((amount - 150000) / 500) * 3.35);
            } else {
                out.value = 935 + (Math.ceil((amount - 200000) / 500) * 3.9);
            }
        } else {
            if ((amount - 200000) <= 350000) {
                out.value = 2735 + (Math.ceil((amount - 200000) / 500) * 4.8);
            } else if ((amount - 550000) <= 300000) {
                out.value = 4655 + (Math.ceil((amount - 555000) / 500) * 5.3);
            } else if ((amount - 850000) <= 150000) {
                out.value = 7835 + (Math.ceil((amount - 850000) / 500) * 5.8);
            } else {
                out.value = 9575 + (Math.ceil((amount - 1000000) / 500) * 6.05);
            }
        }
    }
    normalrtfCalc(amount);
};