0

I am building a calculator that gives the state specific sales tax of a real estate transaction. I know my "normalrtfCalc" function works but my issue is getting the "amount" from the form into the function and the result into the output. Any help would be greatly appreciated. Thanks!

Here is my HTML:

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

Here is my JS:

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);
            }
        }
    }
};
3
  • Which ones out of form, out and amount aren't working? Can you try console.log(var) for each of them? Commented Mar 10, 2013 at 23:34
  • Please do not edit your question while it is being answered. That is known as a chameleon question, and they are not appreciated here. Commented Mar 10, 2013 at 23:44
  • from what I understand (which is very little) var form is to call the input and output form values and allow them to be altered by my function. I am not getting a value in my output, so it would be "out" that is not working. Commented Mar 10, 2013 at 23:44

1 Answer 1

1

There are several things wrong with your code. I will post it below and explain in comments:

function updateOutput() {
    var form = document.getElementById("rtfCalc");
    var out = form.elements["transfer_fee"];
    var amount = parseInt(form.elements["sale_amount"].value);

    function normalrtfCalc(amount) { // an equal sign(=) before the opening curly bracket is invalid syntax; remove it, and execute the function as stated below, and your code works.

        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); //you have to call the function in order for it to execute.
};

DEMO

Sign up to request clarification or add additional context in comments.

5 Comments

@user2108839 If this answer solved your problem, please consider accepting it(when it lets you), by clicking the outlined checkmark to the left of the answer, under the down arrow.
I removed the "=" (typo) and called the function but I'm still not getting a new value in my "output" field in my form
@user2108839 I find such to be strange, given the demo I linked above is working fine. What browser are you testing this in?
@user2108839 It's working fine for me in safari. Could you update your code under another header, showing what you currently have?
I take it back its working now!! Thanks so much you were a big help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.