JavaScript Discount Example 1

The JavaScript on this page demonstrates how you can create your own JavaScripts - with your own custom discount logic - to implement discounts based on subtotal, quantity, etc.

Note 1: In this example, the "checkDiscount()" JavaScript is called via the page's "onLoad" function. You can setup your script to be called at any time and via any JavaScript event.

Note 2: IMPORTANT! Unlike the uShopDiscount1 applet, this JavaScript will only set the discount based the current subtotal or quantity. This means that if a customer modifies the cart contents, the function will need to be called again to check if the discount rate has changed. Thus, for this reason, it is recommended that any custom discount JavaScript that you make, be located on the same page as your uShopOrderButton applet. This will ensure that the discount rate is updated properly before the customer begins the ordering process.


<SCRIPT LANGUAGE="Javascript">
function checkDiscount()
   // Get the subtotal.
   var subtotal = document.uShopJSI.getSubtotal();

   // Get the total quantity.
   var quantity = document.uShopJSI.getTotalQuantity();

   // For this example, give a 10% discount the subtotal is 
   // greater than $100.

   if (subtotal >= 100)
      // Call the setDiscountRate() subroutine to set the discount rate.
      // Call the setDiscountRate() subroutine to reset the discount rate.

Note: Don't forget to add the uShopJSI applet to your page too:
<APPLET CODE="uShopJSI.class" CODEBASE="../classes/" NAME="uShopJSI" WIDTH="2" HEIGHT="2">

More Information:

For more information about creating and using your own JavaScripts with uShop, see uShop and Java Scripts.