需要Javascript折扣帮助

时间:2017-11-03 16:05:34

标签: javascript

我有这个Javascript函数,折扣适用于FlavorBlue或FlavorRed。我试图将数量加在一起,但它没有按预期工作。目标是获得50%的数量2种口味蓝色或红色。我搜索了这个网站寻求帮助,直到脸上出现蓝色和红色......任何见解都会受到极大的重视。提前谢谢。

.js文件:

function ordertotals()
{
var FlavorBluetotal = (order.selectFlavorBlueQuantity.value * 
FlavorBlueprice.value);
document.getElementById('FlavorBluetotal').innerHTML = FlavorBluetotal;
order.FlavorBluetotalvalue.value = FlavorBluetotal;
var FlavorRedtotal = (order.selectFlavorRedQuantity.value * 
FlavorRedprice.value);
document.getElementById('FlavorRedtotal').innerHTML = FlavorRedtotal;
order.FlavorRedtotalvalue.value = FlavorRedtotal;
var FlavorBluecasetotal = (order.selectFlavorBlueCaseQuantity.value * 
FlavorBluecaseprice.value);
document.getElementById('FlavorBluecasetotal').innerHTML = 
FlavorBluecasetotal;
order.FlavorBluecasetotalvalue.value = FlavorBluecasetotal;
// var total = FlavorBluetotal + FlavorRedtotal + FlavorBluecasetotal;
// document.getElementById('ordertotal').innerHTML = total;
// order.ordertotalvalue.value = total;
var totala = 0;
var totalb = 0;
var totalc = 0;
var quantity = (order.selectFlavorBlueQuantity.value + 
order.selectFlavorRedQuantity.value);
// document.getElementById("insert").innerHTML = quantity;
if (order.selectFlavorBlueQuantity.value > 1) {
quantitya = (order.selectFlavorBlueQuantity.value);
var price = 29;
if (quantitya % 2 == 0) {
//calculate here buy one get one half price
real = ((quantitya/2)*price);
half = ((quantitya/2)*(price/2));
totala = (real+half);
} else {
quantitya = (quantitya-1);
real = ((quantitya/2)*price);
half = ((quantitya/2)*price/2);
totala = (real+half+price);
}
} else {
if (order.selectFlavorRedQuantity.value > 1) {
quantityc = (order.selectFlavorRedQuantity.value);
var price = 29;
if (quantityc % 2 == 0) {
//calculate here buy one get one half price
real = ((quantityc/2)*price);
half = ((quantityc/2)*(price/2));
totalc = (real+half);
} else {
quantityc = (quantityc-1);
real = ((quantityc/2)*price);
half = ((quantityc/2)*price/2);
totalc = (real+half+price);
}
}
}
if (order.selectFlavorBlueQuantity.value == 1 && 
order.selectFlavorRedQuantity.value == 1) {
var quantityb = 2;
var price = 29;
if (quantityb % 2 == 0) {
//calculate here buy one get one half price
real = ((quantityb/2)*price);
half = ((quantityb/2)*(price/2));
totalb = (real+half);
} else {
quantityb = (quantityb-1);
real = ((quantityb/2)*price);
half = ((quantityb/2)*price/2);
totalb = (real+half+price);
}
}
// if (order.selectFlavorBlueQuantity.value == 1 || 
order.selectFlavorRedQuantity.value == 1) {
// var quantityd = 1;
// var price = 29;
// totald = (quantityd * price);
// } else {
// }
// total = (totala + totalb + totalc + totald + FlavorBluecasetotal);
total = (totala + totalb + totalc + FlavorBluecasetotal);
document.getElementById('ordertotal').innerHTML = total;
order.ordertotalvalue.value = total;
}

php文件:

//Inventory
echo "<tr><td colspan='2'><u>Select Inventory:</u></td></tr>";
//Quantity Flavor Blue
echo "<tr><td>Quantity of Flavor Blue:</td><td>";
echo "<label>$</label><input type='text' id='FlavorBlueprice' 
name='FlavorBlueprice' maxlength='4' value='$FlavorBlueprice' 
style='width:20px;'>&nbsp;<label>X</label>&nbsp;";
echo "<input type='text' id='selectFlavorBlueQuantity' 
name='selectFlavorBlueQuantity' maxlength='4' 
value='$selectFlavorBlueQuantity' onchange='ordertotals();' 
style='width:20px;'>";
echo "</select><label id='asterisk'>&nbsp;*</label>";
echo "&nbsp;<label>=</label>&nbsp;<label>$</label><label 
id='FlavorBluetotal'></label>";
echo "</td></tr>";

//Quantity Flavor Red
echo "<tr><td>Quantity of Flavor Red:</td><td>";
echo "<label>$</label><input type='text' id='FlavorRedprice' 
name='FlavorRedprice' maxlength='10' value='$FlavorRedprice'  
style='width:20px;'>&nbsp;<label>X</label>&nbsp;";
echo "<input type='text' id='selectFlavorRedQuantity' 
name='selectFlavorRedQuantity' maxlength='4' 
value='$selectFlavorRedQuantity' onchange='ordertotals();' 
style='width:20px;'>";
echo "</select><label id='asterisk'>&nbsp;*</label>";
echo "&nbsp;<label>=</label>&nbsp;<label>$</label><label 
id='FlavorRedtotal'></label>";
echo "</td></tr>";

//Quantity Flavor Blue
echo "<tr><td>Quantity of Flavor Blue Case:</td><td>";
echo "<label>$</label><input type='text' id='FlavorBluecaseprice' 
name='FlavorBluecaseprice' maxlength='10' value='$FlavorBluecaseprice' 
style='width:20px;'>&nbsp;<label>X</label>&nbsp;";
echo "<input type='text' id='selectFlavorBlueCaseQuantity' 
name='selectFlavorBlueCaseQuantity' maxlength='4' 
value='$selectFlavorBlueCaseQuantity' onchange='ordertotals();' 
style='width:20px;'>";
echo "</select><label id='asterisk'>&nbsp;*</label>";
echo "&nbsp;<label>=</label>&nbsp;<label>$</label><label 
id='FlavorBluecasetotal'></label>";
echo "</td></tr>";

//Total
echo "<tr><td>Total:</td><td><label>$</label><label id='ordertotal'></td>
</tr>";
echo "<tr><td colspan='2'><hr></td></tr>";

1 个答案:

答案 0 :(得分:0)

如果别嵌套在另一个内部,我就错了。简单的修复。