开发者

Why on earth won't this Javascript program run?

开发者 https://www.devze.com 2023-04-11 13:07 出处:网络
Just trying to make a simple calculator in javascript.When I try to run it, nothing happen开发者_如何学编程s.I assume its something really simple, but I just can\'t figure it out. Any ideas?I apprecia

Just trying to make a simple calculator in javascript. When I try to run it, nothing happen开发者_如何学编程s. I assume its something really simple, but I just can't figure it out. Any ideas? I appreciate your help.


Your regex is malformed; missing a /. And you have closing html tags in the middle of all your stuff (instead of at the end). And you call CalcMortage and attach the results as the click handler, rather than the method itself (because of the closing () in onclick = CalcMortgage();). And you force multiple digits in the regex (like I can't put "5" for percentage).

Other than that it's fine.


You're assigning the return value (which is undefined) to the onclick handler right here:

document.getElementById("mortgageCalc").calculateMortgage.onclick = CalcMortgage ();

Try dropping the "call this function" parentheses:

document.getElementById("mortgageCalc").calculateMortgage.onclick = CalcMortgage;


It looks like you have a function call to CalcMortgage before you even define it:

document.getElementById("mortgageCalc").calculateMortgage.onclick = CalcMortgage ();

Consider putting this after the definiton of CalcMortgage:

document.getElementById("mortgageCalc").calculateMortgage.onclick = CalcMortgage;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号