我的问题是为什么当我单击按钮时,唯一显示的是这个“价格表”,而所有其他带有变量的行都被省略了。
function showmessage() {
var sendcost, totalcost;
if (document.pricelist.total.value<11) {
sendcost = 3;
}
else {
sendcost = 2;
}
if (document.pricelist.option.checked) {
sendcost = parseInt(document.pricelist.option.value) + parseInt(sendcost);
}
totalcost = parseInt(sendcost) + parseInt(document.pricelist.total.value);
document.write("Pricelist","</br>");
document.write("Products price: "+document.pricelist.total.value+"</br>");
document.write("Send fee: "+sendcost+"</br>");
document.write("Total cost: "+totalcost+"</br>");
}
<form name="pricelist">
Tuna Salad = 4 <input type="checkbox" name="choice" value="4" onchange="checkTotal()" /></br>
Pasta = 13 <input type="checkbox" name="choice" value="13" onchange="checkTotal()" /></br>
Milk = 3 <input type="checkbox" name="choice" value="3" onchange="checkTotal()" /></br>
Chocolate = 2 <input type="checkbox" name="choice" value="2" onchange="checkTotal()" /></br>
Same day delivery<input type="checkbox" name="option" value="5" /></br>
Total: <input type="text" size="2" name="total" value="0"/>
<input type="button" value="Procceed to checkout" onclick='return showmessage();' />