0

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
};

bsekula
  • 914
  • 1
  • 9
  • 25

1 Answers1

0

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>
prasanth
  • 22,145
  • 4
  • 29
  • 53