您好我正在尝试使用 HTML 创建一个表单,其中用户可以在表单 1 和表单 2 中插入数字。一旦 2 个表单填充了数字,总数会自动显示在下一行,没有提交按钮。
请注意,表单是 Django Forms
这是我尝试过的。
var item_1_amount = document.getElementById("item_1_amount");
var item_2_amount = document.getElementById("item_2_amount");
var total = item_1_amount.value + item_2_amount.value
item_1_amount.onkeyup = function () {
document.getElementById("Total").innerHTML = total.value;
};
<tr>
<td><h6 style="float:left; margin-right:5px; margin-top:7px">$</h6>
<input
autocomplete="off"
type="number"
class="form-control w-25"
name="item_1_amount"
id="item_1_amount"
style="float:left"/>
</td>
<td><h6 style="float:left; margin-right:5px; margin-top:7px">$</h6>
<input
autocomplete="off"
type="number"
class="form-control w-25"
name="item_2_amount"
id="item_2_amount"
style="float:left"/>
</td>
</tr>
<tr>
<th>Total</th>
<th id="Total">$$</th>
</tr>