I'm fairly new to JavaScript and wanted to convert one of my calculation spreadsheets to something I can use on a web page. However, the calculation gives me an incorrect result.
Here's my JavaScript:
<script type="text/javascript" language="JavaScript">
function calc() {
var onerepmax = document.wodCalculate.oneRepMax.value;
var percent = document.wodCalculate.percentOfOneRepMax.value / 100;
var addkg = document.wodCalculate.plusKg.value;
var zwischenschritt = onerepmax * percent;
var gewicht = zwischenschritt + addkg;
document.getElementById("weight").innerHTML = gewicht;
};
</script>
and here's the HTML:
<form action="" id="wodCalculate" name="wodCalculate">
<table cellspacing="0" cellpadding="10" border="0">
<tr><td>1 Rep Max</td><td><input type=text name="oneRepMax" value=""> kg<br></td></tr>
<tr><td>% vom 1RM</td><td><input type=text name="percentOfOneRepMax" value=""> %<br></td></tr>
<tr><td>Plus x kg</td><td><input type=text name="plusKg" value=""> kg<br></td></tr>
<tr><td><input type="button" value="Calculate" onClick="calc()"></td></tr>
</table>
</form>
<div id="weight">Weight</div>
It works fine up to the point of multiplying the "onerepmax" with the "percent". However, once it gets to the point of adding the "addkg" to the result of the multiplication (i.e. giving me the "gewicht"), the result becomes incorrect.
For example, I want to get 10% of 100kg and add 10kg. Instead of 20kg, the calculation result is 1010.
Thanks for your help!