用于生成折扣的 AJAX if 语句帮助
我有一个问题,也许有人可以帮助我解决。
我正在为客户创建一个订单表单脚本,用户可以在其中填写包含简单计算器的查询表单。因此,用户将能够输入姓名、地址、电子邮件等。
除此之外,还有四个文本框,要求填写他们所询问的产品的参考号。然后是数量文本框、价格文本框和总计文本框。
重复 3 次,然后出现一个总计文本框。因此,通过使用 JavaScript,它会根据填写的内容自动生成总计。这是创建的 JavaScript 代码:
function calculate() { QtyA = 0; QtyB = 0; QtyC = 0; TotA = 0; TotB = 0; TotC = 0; PrcA = 0; PrcB = 0; PrcC = 0; //Below the code for the price if (document.ofrm.prcA.value > "") { PrcA = document.ofrm.prcA.value }; document.ofrm.prcA.value = eval(PrcA); if (document.ofrm.prcB.value > "") { PrcB = document.ofrm.prcB.value }; document.ofrm.prcB.value = eval(PrcB); if (document.ofrm.prcC.value > "") { PrcC = document.ofrm.prcC.value }; document.ofrm.prcC.value = eval(PrcC); //Below the code for the quanity if (document.ofrm.qtyA.value > "") { QtyA = document.ofrm.qtyA.value }; document.ofrm.qtyA.value = eval(QtyA); if (document.ofrm.qtyB.value > "") { QtyB = document.ofrm.qtyB.value }; document.ofrm.qtyB.value = eval(QtyB); if (document.ofrm.qtyC.value > "") { QtyC = document.ofrm.qtyC.value }; document.ofrm.qtyC.value = eval(QtyC); //Get the totals for the calculator (May need to be altered) TotA = QtyA * PrcA; document.ofrm.totalA.value = dm(eval(TotA)); TotB = QtyB * PrcB; document.ofrm.totalB.value = dm(eval(TotB)); TotC = QtyC * PrcC; document.ofrm.totalC.value = dm(eval(TotC)); Totamt = eval(TotA) + eval(TotB) + eval(TotC) ; document.ofrm.GrandTotal.value = dm(eval(Totamt)); }
我现在想做的是。有一个使用 AJAX 的小折扣脚本。因此,如果总额在
£55-£129 之间,用户将获得 10% 的折扣 £130-£249 用户将获得 15% 折扣 £250+用户将获得25%的折扣。
我希望有人能帮我解决这个问题,谢谢。
I have a problem that maybe someone could help me with.
I'm creating a order form script for a client where the user can fill out an enquiry form that contains a simple calculator. So the user will be able to type in name, address, email etc.
As well as this there are four text boxes saying to fill out a reference number of the product they are enquiring about. Then a text box for quantity, a text box for price, and a text box for the total.
This is repeated 3 times and then there is a text box for a grand total. So by using JavaScript it automatically generates a grand total depending on what they fill out. This is the JavaScript code is created:
function calculate() { QtyA = 0; QtyB = 0; QtyC = 0; TotA = 0; TotB = 0; TotC = 0; PrcA = 0; PrcB = 0; PrcC = 0; //Below the code for the price if (document.ofrm.prcA.value > "") { PrcA = document.ofrm.prcA.value }; document.ofrm.prcA.value = eval(PrcA); if (document.ofrm.prcB.value > "") { PrcB = document.ofrm.prcB.value }; document.ofrm.prcB.value = eval(PrcB); if (document.ofrm.prcC.value > "") { PrcC = document.ofrm.prcC.value }; document.ofrm.prcC.value = eval(PrcC); //Below the code for the quanity if (document.ofrm.qtyA.value > "") { QtyA = document.ofrm.qtyA.value }; document.ofrm.qtyA.value = eval(QtyA); if (document.ofrm.qtyB.value > "") { QtyB = document.ofrm.qtyB.value }; document.ofrm.qtyB.value = eval(QtyB); if (document.ofrm.qtyC.value > "") { QtyC = document.ofrm.qtyC.value }; document.ofrm.qtyC.value = eval(QtyC); //Get the totals for the calculator (May need to be altered) TotA = QtyA * PrcA; document.ofrm.totalA.value = dm(eval(TotA)); TotB = QtyB * PrcB; document.ofrm.totalB.value = dm(eval(TotB)); TotC = QtyC * PrcC; document.ofrm.totalC.value = dm(eval(TotC)); Totamt = eval(TotA) + eval(TotB) + eval(TotC) ; document.ofrm.GrandTotal.value = dm(eval(Totamt)); }
What I'm trying to do now is. Having a small discount script using AJAX. so if the total is between
£55-£129 the user will get 10% discount
£130-£249 the user will get 15% discount
£250+ the user will get 25% discount.
I hope someone can help me with this thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你的函数工作正常并且你可以使用jquery,你可以这样做:
if your function work correctly and you can work with jquery you can do this: