I’ve failed to get this calculation to work. It is to calculate compound interest on money in a building society.
compound interest = investment(1+interest rate/100)*amount of years.
It all works fine -until the calculation is put in. I have put in some alerts to pass the values of the variables back to screen and they are all ok….
When the button is pressed it should show the amount including interest in an alert box.
Here is my code:
<html>
<head>
<title>Compound Interest Calculator</title>
<script language = “Javascript”>
var myinvestamount =0;
var myinterestrate =0;
var mymonthstoinvest =0;
var mycompoundinterest=0;
function checkform()
{
var valid = true;
myinvestamount = CustForm.Amount.value;
myinterestrate = CustForm.Rate.value;
mymonthstoinvest = CustForm.Time.value;
if (myinvestamount ==””){
alert(“No data entered in Amount to Invest Textbox”);
valid=false;
}
if (myinterestrate ==””) {
alert(“No data entered in Intrest Rate Textbox”);
valid=false;
}
if (mymonthstoinvest ==””) {
alert(“No data entered in Time to Invest Textbox”);
valid=false;
}
return valid;
}
function calculate()
{
alert(“amount ” + myinvestamount + ” rate ” + myinterestrate + ” months ” + mymonthstoinvest);
mycompoundinterest = myinvestamount((1+myinterestrate/100)*mymonthstoinvest/12);
window.alert (mycompoundinterest);
window.alert (“done calculate”);
}
function displaypopup()
{
window.alert (“done displaypopup”);
}
function doall()
{
checkform()
calculate()
window.alert (“done doall”);
return true;
}
</script>
</head>
<body>
<h3>Please Enter Your Data in the Boxes Below</h3>
<form name = “CustForm” onsubmit = “return doall()” method = “post”>
Total amount to invest(£) <input type = “text” size = 50 name = “Amount”><p>
Interest Rate <input type = “text” size = 10 name = “Rate”><p>
Number of Months to Invest <input type = “text” size = 10 name = “Time”><p>
<input type = submit value = “Submit”><p>
</form>
</body>
</html>
Hope someone can help……I’m desperate with this!