I have 2 <p> tags and an input field, wrapped in a while loop
<p id="price"></p>
<input id="quantity" oninput="calculate(<?php echo $cprice; ?>)" type="text" name="quantity">
<p id="total"></p>
I want to use JavaScript to perform arithmetic.
I want to multiply price and quantity and display the result in total. Without the while loop, it works but with the while loop, it only updates the first field.
function calculate(price) {
var quantity = document.getElementById('quantity').value;
var result = document.getElementById('total');
var myResult = price * quantity;
document.getElementById('total').innerHTML = myResult;
}
I don't know how to dynamically update the total tag with js
whileloop