开发者

AJAX if Statement Help for generating Discounts

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.q开发者_如何学编程tyC.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.


if your function work correctly and you can work with jquery you can do this:


.
.

setGrandTotalWithDiscount(dm(eval(Totamt)));

}

function setGrandTotalWithDiscount(gtotal)
{
$.ajax({
  url: "valueWithDiscount.php?gtotal="+gtotal,
  success: function(data){
   document.ofrm.GrandTotal.value = data;
  }
});
}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜