I'm writing a script that does a calculation with text inputs in a form. For some reason, my calculation is performed only once per page load. I have to refresh the page to get the function to run again when I press a "calculate" button.
Here's the HTML for my buttons:
<input type="button" value="Calculate" onclick="calculate(high, low, common);" />
<input type="reset" />
<div id="result"></div>
Here is the calculate function (the variables are defined elsewhere):
var calculate = function (high, low, common) {
if (high.length < 1 || low.length < 1 || common.length <1) {
document.getElementById('result').innerHTML="Please enter a number for all fields.";
} else {
if ((high - common) > (common - low)) {
document.getElementById('result').innerHTML="Result 1.";
} else if ((common - low) > (high - common)) {
document.getElementById('result').innerHTML="Result 2.";
} else if ((common - low) === (high - common)) {
document.getElementById('result').innerHTML="Result 3.";
}
}
};
Am I doing something that prevents the function from running more than once per page load?