This code that I wrote is meant to call the calculateInterest
function and return false. However, the page does not appear to call the function or return false. Thank you for the help.
HTML
<form onsubmit="return calculateInterest(); return false;" id="interest_calc" name="interest_calc" method = "get";>
...
<input type="submit" id="calculate" value="Calculate">
<input type="button" id="calculate" value="test" onclick="return calculateInterest();">
</form>
JS
var $ = function (id)
{
return document.getElementById(id);
};//DOM function
...
//DEBUG alert (iPercentage);
var calculateInterest; = function ()
{
alert ("function called");
return false
};
Remove the unnecessary ;
on script .And no need a return false
on submit
function call in html.Because its already there in calculateinterest
function
var $ = function(id) { return document.getElementById(id); } var calculateInterest = function() { alert("function called"); return false };
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form onsubmit="return calculateInterest()" id="interest_calc" name="interest_calc" method="get" ;> ... <input type="submit" id="calculate" value="Calculate"> <input type="button" id="calculate" value="test" onclick="return calculateInterest();"> </form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.