<input type="number" name="quantity" id="quantity">
<span id="price">4000</span>
<input type="text" value="" id="total" readonly>
<input type="button" value="calculate Total Price" onClick="calculate()">
I have a form with fields for quantity and price, and I want to calculate the total price using a JavaScript function when the user clicks the calculate button. However, the result is currently coming out as NaN. Here is the JavaScript function I am using:
function calculateTotalPrice() {
var quantity = document.getElementsByName('quantity').value;
var price = document.getElementById('price');
var parsedPrice = parseInt(price);
var total = quantity * parsedPrice;
document.getElementById("total").value = total;
}