0

我使用两个函数来处理两个输入,然后使用第三个函数将结果与作为输出的第三个函数的结果进行比较。

这是我的 HTML:

<form id="standardPremuimcalc" oninput="updateOutput()">
    <input name= "new_loan_amount" type="number" value="0"/>
    <input name= "purchase_price" type="number" value="0"/>
    <output name= "premuim_rate" for="new loan amount purchase price"></output>
</form>

这是我的js:

function updateOutput(){

var form = document.getElementById("standardPremiumcalc");
var out = form.elements["premium_rate"];
var amount = parseInt(form.elements["new_loan_amount"].value);
var purchase = parseInt(form.elements ["purchase_price"].value);
var loanCalc = lender()
var ownCalc = owner()

function lender(amount){
if (amount<=100000){
    if (amount<=40000){
        return 200;
    }else{
        return (Math.ceil(amount/1000))*5;
    }
}else{
    if ((amount-100000)<=500000){
        return 500+(Math.ceil((amount-100000)/1000)*3.95);
    }else if ((amount-500000)<=2000000) {
        return 2080+(Math.ceil((amount-500000)/1000)*2.65);
    }else{
        return 6055+(Math.ceil((amount-2000000)/1000)*2);
    }
} 
}
function owner(purchase) {
if (purchase<=100000){
    if (purchase<=40000){
        return 200;
    }else{
        return (Math.ceil(purchase/1000))*5;
    }
}else{
    if ((purchase-100000)<=500000){
        return 500+(Math.ceil((purchase-100000)/1000)*3.95);
    }else if ((purchase-500000)<=2000000) {
        return 2080+(Math.ceil((purchase-500000)/1000)*2.65);
    }else{
        return 6055+(Math.ceil((purchase-2000000)/1000)*2);
    }
} 
}
function standardPremium (loanCalc,ownCalc) {
    if (loanCalc-ownCalc>0) {
        out.value = loanCalc+ownCalc
    }else{
        out.value = loanCalc
}
}
    lender(amount)
    owner(purchase)
    standardPremium(loanCalc,ownCalc)
};

我没有得到输出字段,我错过了什么?

4

2 回答 2

0

first: your form id has the same misspelling.

second: you don't pass an amount variable to your two functions lender and owner.

于 2013-04-25T07:06:41.003 回答
0

premuim_rate需要premium_rate在您的 HTML 中

于 2013-04-25T06:24:16.793 回答