I want to get the value of the totalPrice into the HTML tag of input with id="totalprice" but it cant . the code is below:
function price() {
var bagPrice, shirtPrice, totalPrice, x;
bagPrice = document.getElementById("bag").value;
shirtPrice = document.getElementById("shirt").value;
totalPrice = document.getElementById("totalprice").value;
totalPrice = bagPrice * shirtPrice;
}
<h3>You can make your orders here</h3>
<form id="myform">
How many tote bags / sweatshirt are you purchasing ?
<input type="number" id="bag" name="bag" value=""> <br>
<label for="shirt">What are the price of tote bag / sweatshirt are you purchasing?</label>
<input type="number" id="shirt" name="shirt" value=""> <br> <br>
<label for="totalprice">Your total price is:</label>
<input type="number" id="totalprice" name="totalprice" value="5" readonly> <br>
<button type="button" onclick="price()">Calculate</button>
</form>
strings. If you want to do calculations with form values, you need to cast them to the properNumbertype first.totalPrice = document.getElementById("totalprice").value;does not create a connection between the variable and the input value, meaning if either of them changes later on, the other will be unaffected. You want to do the opposite:document.getElementById("totalprice").value = bagPrice * shirtPrice;.