Итак ... с вашим кодом бесчисленное множество проблем, но самое главное - читабельность. Пожалуйста, научитесь структурировать свой код.
несколько ошибок, на которые стоит обратить внимание:
- Нет метода 'on-submit'
- Прочтите соглашение об именах JS функций, так как «Calculate total ()» не является допустимым именем, которое вы используете для кнопки вычисления итогов.
- Вы пытаетесь получить элементы по идентификаторам но вы забыли его назначить.
- Снова соглашение об именах: «Количество» используется для хранения значения поля ввода количества, но вы использовали «количество» в вычисление.
- вы не можете установить внутренний Html для поля ввода.
- вы присвоили строковое значение для 'totalPrice', а затем использовали то же самое при умножении.
<html>
<body>
<div id="form">
<form name="this form" method="post" action="">
<label> Item description</label>
<input type="text" name="Item description" value="Red copper bowl" />
<label>Quantity</label>
<input type="number" id="quantity" name="quantity" value="1" />
<label> Price</label>
<input type="number" id="price" name="price" value="450" readonly="" />
<label>total price</label>
<input type="number" id="totalPrice" name="" value="450" />
<input type="button" value="Calculate Total" onclick="calculateTotal()" />
<input type="button" value="submit" onclick="submit()" />
<input type="button" value="reset" onclick="clearTotal()" />
</form>
</div>
<script type="text/JavaScript">
function calculateTotal() {
//const totalPrice = "450";
let quantity = document.getElementById("quantity").value;
let price = document.getElementById("price").value;
let total = quantity * price;
console.log(total)
document.getElementById("totalPrice").value = total;
}
function clearTotal() {
document.getElementById("quantity").value = 1;
document.getElementById("totalPrice").value = 450;
}
function submit() {
return window.confirm( "is the information correct ? \n ItemDescription = RedBowl nQuantity = 1 nPrice = $450" );
}
</script>
</body>
</html>
и последнее, но не менее важное: https://www.w3schools.com/js/js_conventions.asp