183
rated 0 times
[
189]
[
6]
/ answers: 1 / hits: 30667
/ 9 Years ago, sat, march 28, 2015, 12:00:00
I am trying to subtract two numbers from an HTML Input form and populate the result into another input field using JavaScript. Unfortunately i am new to JavaScript so please be so kind to point me in the right direction.
Here's my HTML code.
<div class=form-group col-lg-6>
<label for=exampleInputText>Total Price</label>
<input type=text name=totalval class=form-control id=totalval>
</div>
<div class=form-group col-lg-6>
<label for=exampleInputText>Initial Deposit</label>
<input type=text name=inideposit class=form-control id=inideposit>
</div>
<div class=form-group col-lg-6>
<label for=exampleInputText>Outstanding Dues</label>
<input type=text name=remainingval class=form-control id=remainingval >
</div>
Here is my JavaScript code:
<script type=text/javascript>
var total = parseInt(document.getElementById(totalval).value);
var val2 = parseInt(document.getElementById(inideposit).value);
var ansD = document.getElementById(remainingval);
ansD.value = total - val2;
</script>
More From » html