I have a forum where I want to do a simple calculation in JavaScript and when I click a button, a textbox value is entered from my function. How can I do this? My code does not seem to work.
function calculate() {
var odometerStart = document.getElementById('odometerStart').value;
var odometerEnd = document.getElementById('odometerEnd').value;
var distance = document.getElementById('distance');
if (distance)
{
distance.value = odometerEnd - odometerStart;
}
}
Odometer: Start <input type="number" name="odometer[Start]" id="odometerStart" min="0" max="999999" placeholder="0" class="required"/><br/>
Odometer: End <input type="number" name="odometer[End]" id="odometerEnd" min="0" max="999999" placeholder="999999" class="required"/><br/>
Distance <input type="text" name="distance" placeholder="0.00"/><br/>
<input type="button" name="calculate" value="Calculate" onclick="calculate()"/>