我前几天得到了一些帮助,基于选择多个复选框并减去选择1个以上服务的折扣。是否可以显示实际总数和低于折扣总额
例:
[X] - 选项1 = $ 50
[X] - 选项2 = $ 50
[] - 选项3 = $ 50
[] - 选项4 = $ 50
实际总数= $ 100
折扣总额= $ 75
代码如下:
<script>
function checkTotal() {
document.listForm.total.value = '';
var sum = 0; var o = 0;
for (i=0;i<document.listForm.choice.length;i++) {
if (document.listForm.choice[i].checked) {
sum = sum + parseInt(document.listForm.choice[i].value);
o++;
}
}
if (o>1) {sum=sum-25;}
document.listForm.total.value = sum;
}
</script>
<form name="listForm">
<input type="checkbox" name="choice" value="50" onChange="checkTotal()"/>Back Massage - 30 Minutes<br/>
<input type="checkbox" name="choice" value="50" onChange="checkTotal()"/>Neck Massage - 30 minutes<br/>
<input type="checkbox" name="choice" value="50" onChange="checkTotal()"/>Shoulder Massage - 30 Minutes<br/>
<input type="checkbox" name="choice" value="30" onChange="checkTotal()"/>Head Massage - 15 minutes<br/>
Total:
<input type="text" size="2" name="total" value="0"/>
</form>