Javascript代码中的按钮未计算公式

Javascript代码中的按钮未计算公式,javascript,html,Javascript,Html,我写了所有代码,但当我运行网页时,按钮根本不会计算答案并将字符串发送到每月付款文本框。这是一个使用HTML和Javascript的月度付款计算器。我不知道我做错了什么,非常感谢你的帮助 我使用的是netbeans 8,每次Chrome打开它进行调试时,我都会收到一个错误代码。我不确定我的代码是否正确,浏览器是否没有运行该功能,或者我的代码是否不正确。我觉得我的错误很小 <!DOCTYPE html> <html> <head> <

我写了所有代码,但当我运行网页时,按钮根本不会计算答案并将字符串发送到每月付款文本框。这是一个使用HTML和Javascript的月度付款计算器。我不知道我做错了什么,非常感谢你的帮助

我使用的是netbeans 8,每次Chrome打开它进行调试时,我都会收到一个错误代码。我不确定我的代码是否正确,浏览器是否没有运行该功能,或者我的代码是否不正确。我觉得我的错误很小

<!DOCTYPE html>
<html>
    <head>
        <title>Monthly Payment Calculator</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>

    <body>
        <form name="mpForm" action=""> 
                <table border="0">
                    <tbody>
                        <tr>
                            <td>Enter Loan:</td>
                            <td><input id='loanAmt' type="text"  name="loanAmt" value="" /></td>
                        </tr>
                        <br>
                        <tr>
                        <td>Select Rate</td>
                        <td><select name="Rate">
                            <option value=.04>3%</option>
                            <option value=045>3.5%</option>
                            <option value=.05 >4%</option>
                            <option value=.055>4.5%</option>
                            <option value=.06>5%</option>
                            <option value=.055>5.5%</option>
                            <option value=.06>6%</option>
                            </select></td>
                        </tr>
                        <tr>
                            <td>Select Year</td>
                            <td><input type="radio" name="Year" value=10 />10 year<br>
                            <input type="radio" name="Year" value=15 />15 year<br>
                            <input type="radio" name="Year" value=30 />30 year<br>
                            </td>
                        </tr>
                        <tr>
                            <td>Monthly Payment: </td>
                            <td><input type="text" name="MP"  /></td>
                        </tr>
                        <tr>
                            <td><input type="button" value=“computeMP" name="btnCompute" onClick=“computeMP()" /></td>
                        </tr>
                </tbody>
            </table> 
        </form>
<script>
function computeMP(){
myLoan=parseFloat(document.mpForm.loanAmt.value);
myRate=parseFloat(document.mpForm.Rate.options[document.mpForm.Rate.selectedIndex].value);
if (document.mpForm.Year[0].checked)
    {myYear=10;}
else if (document.mpForm.Year[1].checked)
    {myYear=15;}
else
    {myYear=30;}
MP=(Loan * (myRate/12))/1-Math.pow(1+(myRate/12),-12*myYear));
document.mpForm.mp.value=MP.toString(); 
}
</script>

    </body>
</html>

每月付款计算器
输入贷款:

选择费率 3% 3.5% 4% 4.5% 5% 5.5% 6% 选择年份 10年
15年
30年
每月付款: 函数computeMP(){ myLoan=parseFloat(document.mpForm.loanAmt.value); myRate=parseFloat(document.mpForm.Rate.options[document.mpForm.Rate.selectedIndex].value); 如果(document.mpForm.Year[0]。已选中) {myYear=10;} else if(document.mpForm.Year[1]。选中) {myYear=15;} 其他的 {myYear=30;} MP=(贷款*(myRate/12))/1-Math.pow(1+(myRate/12),-12*myYear)); document.mpForm.mp.value=mp.toString(); }

我希望输出能够解出MP变量中列出的等式。源代码中有一些错误:

  • 按钮中有奇怪的字符
    “ComputeTemp”

  • 名称为MP,但用作MP

  • 变量为myLoan,但与Loan一起使用
这里是源代码工作

函数computeMP(){
myLoan=parseFloat(document.mpForm.loanAmt.value);
myRate=parseFloat(document.mpForm.Rate.options[document.mpForm.Rate.selectedIndex].value);
如果(document.mpForm.Year[0]。选中){myYear=10;}
else如果(document.mpForm.Year[1]。选中){myYear=15;}
否则{myYear=30;}
MP=(myLoan*(myRate/12))/1-Math.pow(1+(myRate/12),-12*myYear);
document.mpForm.MP.value=MP.toString();
}

每月付款计算器
输入贷款:

选择费率 3% 3.5% 4% 4.5% 5% 5.5% 6% 选择年份 10年
15年
30年
每月付款:
您刚刚出现了一些语法错误,应该可以这样做:)


每月付款计算器
输入贷款:

选择费率 3% 3.5% 4% 4.5% 5% 5.5% 6% 选择年份 10年
15年
30年
每月付款: 函数computeMP(){ myLoan=parseFloat(document.mpForm.loanAmt.value); myRate=parseFloat(document.mpForm.Rate.options[document.mpForm.Rate.selectedIndex].value); 如果(document.mpForm.Year[0]。已选中) {myYear=10;} else if(document.mpForm.Year[1]。选中) {myYear=15;} 其他的 {myYear=30;} MP=(myLoan*(myRate/12))/1-Math.pow(1+(myRate/12),-12*myYear); 控制台日志(文档); document.mpForm.mp.value=mp.toString(); }
在提问时始终提供您遇到的错误。寻求调试帮助的问题(“此代码为什么不工作?”)必须包括特定的问题或错误。请参阅:。
<!DOCTYPE html>
<html>
    <head>
        <title>Monthly Payment Calculator</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>

    <body>
        <form name="mpForm" action="">
                <table border="0">
                    <tbody>
                        <tr>
                            <td>Enter Loan:</td>
                            <td><input id='loanAmt' type="text"  name="loanAmt" value="" /></td>
                        </tr>
                        <br>
                        <tr>
                        <td>Select Rate</td>
                        <td><select name="Rate">
                            <option value=.04>3%</option>
                            <option value=045>3.5%</option>
                            <option value=.05 >4%</option>
                            <option value=.055>4.5%</option>
                            <option value=.06>5%</option>
                            <option value=.055>5.5%</option>
                            <option value=.06>6%</option>
                            </select></td>
                        </tr>
                        <tr>
                            <td>Select Year</td>
                            <td><input type="radio" name="Year" value=10 />10 year<br>
                            <input type="radio" name="Year" value=15 />15 year<br>
                            <input type="radio" name="Year" value=30 />30 year<br>
                            </td>
                        </tr>
                        <tr>
                            <td>Monthly Payment: </td>
                            <td><input type="text" name="mp"  /></td>
                        </tr>
                        <tr>
                            <td><input type="button" value="computeMP" name="btnCompute" onClick="computeMP()" /></td>
                        </tr>
                </tbody>
            </table>
        </form>
<script>
function computeMP(){
myLoan=parseFloat(document.mpForm.loanAmt.value);
myRate=parseFloat(document.mpForm.Rate.options[document.mpForm.Rate.selectedIndex].value);
if (document.mpForm.Year[0].checked)
    {myYear=10;}
else if (document.mpForm.Year[1].checked)
    {myYear=15;}
else
    {myYear=30;}
MP=(myLoan * (myRate/12))/1-Math.pow(1+(myRate/12),-12*myYear);
console.log(document);
document.mpForm.mp.value=MP.toString();
}
</script>

    </body>
</html>