如何在数字框中显示复选框和下拉列表的产品

时间:2014-10-19 07:47:11

标签: javascript html

这是我的目录代码。想要显示复选框的值乘以下拉列表的值并将产品输出到。只需使用html和javascript代码。

<table align=center border=1>
<tr colspan=3>
<td colspan=3><h2>Specialty Cakes</h2></td>
</tr>
<tr>
<td><img src=special\blackforest_small.jpg valign=center-right><br><center>Black Forest</td>
<td>Chocolate sponge layered with sugar syrup and Kirsch flavouring, white mousse and dark sweet cherries.</td>
<td><input type="checkbox" id="check1" name="check1" value="550.00"onclick="product1()">Buy P550.00</input><br><input type="number" id="total1" name="total1" value="P0.00"size="8"></input><br>
QTY: <select id="qty1" name="qty1" onchange="product1()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
</td>
</tr>

</table>
<script>
var m = document.getElementById("check1").checked;
function product1(){
var x = document.getElementById("check1").value;
var y = document.getElementById("qty1").value;
var z = 0;
if (m = true){
z = "P" + x * y;
}
document.getElementById("total1").value = z;
}
</script>

1 个答案:

答案 0 :(得分:1)

您输入的id为total1作为type = number - 但是您为其指定了一个文本值P0.00将其类型更改为文本并且它将起作用,或者给它一个数值。