Click to See Complete Forum and Search --> : Calculating user input in forms


superwoman
12-04-2002, 05:32 PM
Help Me Please! I've been working on this code for about a week, I can't figure out how to calculate the user input in the forms. My code is attached. Any help would be greatly appreciated! I tried looking at the answer posted for Snowgirl's question but that really doesn't help me much. Thanks.

<html>
<head>
<title>
calculate interest//Robin Zolinas
</title>
</head>
<body>
<script language="Javascript">
function calculateInterest(){
var principal; principal= document.myForm.principal.value;
var interestRate; interestRate= document.myForm.interestRate.value;
var numberOfYears; numberOfYears= document.myForm.numberOfYears.value;
}
for (var i=0;i<principal;i=i+1){
principal=(document.myForm.principal.value*document.myForm.interestRate.value)+document.myForm.princ ipal.value;
}
</script>
<form name="myForm">
<input type="text" name="principal">Principal<br>
<input type="text" name="interestRate">Interest Rate<br>
<input type="text" name="numberOfYears">Number Of Years<br>
<input type="button" value="Calculate" onClick="calculateInterest()">
</form>
</body>
</html>

superwoman
12-04-2002, 05:52 PM
Okay, I changed my variables and also changed the for loop, where would I insert an alert to bring up the total that was calculated?

superwoman
12-04-2002, 06:20 PM
Thanks Dave! I was able to finally get an alert by puting it after the function. I just need to figure out how to calculate the forms.

spufi
12-05-2002, 11:54 AM
superwoman, did my code in your other thread work? I saw you replied to it, but the e-mail I was sent gave me a incorrect link. I tried to look for the thread, but I don't see it.