I am trying to perform a simple addition with jQuery.
2 input fields and a total price. On click the total is displayed below.
I can get jQuery to perform the calculation, but it wont update the original price and each calculation adds the new calculation next to the total price when I need it to replace it.
Any help appreciated
Dave
$(document).ready(function() {
var currentPrice = $('#totalPrice').text();
$("#calc").click(function() {
var value = $("#price1").val();
var value2 = $("#price2").val();
var newValue = parseInt(value) + parseInt(value2) + parseInt(currentPrice);
$('span').append(newValue);
});
});
<form action="">
<input id="price1"></input><br />
<input id="price2"></input>
<input type="button" value="Calculate" id="calc" />
</form>
<br />
<span id="totalPrice">10</span>