2017-04-25 8 views
0

「計算支払い」をクリックした後、なぜNaNと表示されるのかわかりません。これが起こっていると思う理由は、computeMonthlyPayment()関数、より具体的には計算行のためだけです。私はラジオボタンに関連しているかもしれないと思います。あなたの属性の周りテキストボックスにNaNが表示され、基本的な計算で問題が発生する

<!DOCTYPE html> 
 
    <html> 
 
    <head> 
 
\t <title> Monthly Payment Calculator</title> 
 
    </head> 
 

 
    <script> 
 
\t function computeMonthlyPmt(){ 
 
\t \t var amt = document.MonthlyPmt.LoanAmt.value; 
 
\t \t var r = document.MonthlyPmt.Rate.value; 
 
\t \t var t = document.MonthlyPmt.Year.value; 
 
\t \t document.MonthlyPmt.Payment.value = (amt*(r/12))/(1-Math.pow(1+(r/12),-12*t)); 
 
\t \t 
 
\t } 
 
    </script> 
 

 
    <body> 
 
    <h1> Monthly Payment Calculator </h1> 
 

 
    <form name="MonthlyPmt"> 
 
\t <p> Enter Loan:<input type="text" name="LoanAmt" value="" /> </p> 
 
\t 
 
\t \t 
 
\t <p> Select Rate: </p> 
 
\t <select name="Rate"> 
 
\t \t <option value=0.04>4%</option> 
 
\t \t <option value=0.045>4.5%</option> 
 
\t \t <option value=0.05>5%</option> 
 
\t \t <option value=0.055>5.5%</option> 
 
\t \t <option value=0.06>6%</option> 
 
\t </select> 
 

 
\t <p> Select Term: </p> 
 
\t \t <input type="radio" name="Year" value=10/>10 Years<br> 
 
\t \t <input type="radio" name="Year" value=15/>15 Years<br> 
 
\t \t <input type="radio" name="Year" value=30/>30 Years<br> 
 

 
\t <p> Monthly Payment: </p> 
 
\t \t <input type="text" name="Payment" value="" /><br> 
 
\t \t <input type="button" value="Compute Payment" name="btnCompute" onclick="computeMonthlyPmt()" /> 
 

 
    </form> 
 
    </body> 
 
    </html>

答えて

0

引用符を使用!はい、それらはオプションでもかまいませんが、ここでは後ろに座っています。

年の値は"30/"ではなく、30です。

デバッグそれを:

console.log(amt, r, t) 

function computeMonthlyPmt() { 
 
    var amt = document.MonthlyPmt.LoanAmt.value; 
 
    var r = document.MonthlyPmt.Rate.value; 
 
    var t = document.MonthlyPmt.Year.value; 
 
    document.MonthlyPmt.Payment.value = (amt * (r/12))/(1 - Math.pow(1 + (r/12), -12 * t)); 
 

 
}
<form name="MonthlyPmt"> 
 
    <p> Enter Loan:<input type="text" name="LoanAmt" value="" /> </p> 
 

 

 
    <p> Select Rate: </p> 
 
    <select name="Rate"> 
 
    <option value="0.04">4%</option> 
 
    <option value="0.045">4.5%</option> 
 
    <option value="0.05">5%</option> 
 
    <option value="0.055">5.5%</option> 
 
    <option value="0.06">6%</option> 
 
</select> 
 

 
    <p> Select Term: </p> 
 
    <input type="radio" name="Year" value="10" />10 Years<br> 
 
    <input type="radio" name="Year" value="15" />15 Years<br> 
 
    <input type="radio" name="Year" value="30" />30 Years<br> 
 

 
    <p> Monthly Payment: </p> 
 
    <input type="text" name="Payment" value="" /><br> 
 
    <input type="button" value="Compute Payment" name="btnCompute" onclick="computeMonthlyPmt()" /> 
 

 
</form>

+0

あなたの答えのおかげで、それでもこれを変更した後、私はまだ同じ問題を取得しています。 –

+0

あなたは引用符ですべての値をラップしましたか? – epascarello

+0

それは正しいです –

関連する問題