我有兩個輸入寬度和高度來計算三角形的面積。當你在寬度和高度的每個輸入中鍵入數字時,我需要一個提交按鈕來乘以寬度x高度並將總面積插入到輸入中。乘以兩個變量並將總數插入輸入JavaScript on.click命令
HTML:
<p id="instructions" class="Main">Enter the width and height of your triangle to calculate the area.</p>
<!--Main div-->
<form id="mainform">
Width (b):
<input type="Text" id="width" placeholder="width" >
<div>
Height(h):
<input type="text" id="height" placeholder="height">
</div>
<button type="button" id="total" onclick="calculateArea()">Calculate Area</button>
</form>
<!--Divider-->
<form>
<div id="divider">
</div>
<div id="area">
The area is:
<input type="text" name="txtarea" id="total">
</div>
</form>
</div>
的JavaScript:
function calculateArea() {
var width = document.getElementById('width').value;
var height = document.getElementById('height').value;
var total = document.getElementById('total');
total.value = width * height;
}
JAVA!= JAVASCRIPT – shmosel