I got old code of my apps that using javascript to calculate something, the logic is if 1 textbox filled, another textbox automatic filled, and when the second textbox filled, that another textbox will return text1 - text2, maybe You can look at this fiddle:
HTML:
<label>Price Start</label>
<input type="number" class="form-control" placeholder="Total Harga Diberikan" required="required" name="price" onkeyup="calculate()" id="price" />
<br />
<label>Discount</label>
<input type="number" class="form-control" placeholder="Nominal Potongan" name="jmlvoucher" onkeyup="calculate()" id="jmlvoucher" />
<br />
<label>Total</label>
<input type="number" class="form-control" placeholder="Total yang harus dibayarkan" required="required" name="total" id="total" />
Javascript:
function calculate(){
var num1 = document.getElementById("price").value;
var num2 = document.getElementById("jmlvoucher").value;
var sum=parseFloat(num1)-parseFloat(num2);
document.getElementById('total').value=sum.toString();
}
http://jsfiddle.net/n4anv5qn/2/
Already try to check error, but there's no error. Try to run it, it doesn't works. Any idea why?