home page
JavaScript

Complex Single Item Purchase Demo.

* 2 September, 2004 Fixed tax problem - now multiplied by quantity.
* 23 May, 2004 ZIP code must be entered.
* 6 January, 2004 New and improved.
* 21 August, 2003 Conform to 15 August PayPal release. New variable "lc" must be passed.

The purpose of this is to demonstrate some "plug-in" JavaScript (JS) that can help the Single Item Purchase user of PayPal. It starts with the standard PayPal-supplied HTML from their button factory and makes a few changes to permit the JS interface. You never have to mess with the JS at all - just learn how to interface with it. Here is a list of features...

Following is an example FORM using the JS. Right-click on this page, and then , so you have a reference to what was done in the HTML to interface with the JS. Play with the FORM and see how it works. Following the FORM is a description of the interface into the JS. It occurs in event handlers within the HTML.

The following quantity-based tables may be constructed. They may be called from different places, just as long as they are called before the FORM is evaluated.

  1. Quantity based discount. - SetQD (2, 1, 5, 2);
  2. Quantity based amount. - SetQA (1, 10, 6, 9);
  3. Quantity based handling charges. - SetHN (1, 3, 2, 5);
  4. Quantity based shipping charges. There are two ways to do this. If you charge no shipping at all then you must make a call in the set-list following the sing.js installation of SetSH (0, 0); This is required to make the program work.

[Picture of item] Blah, Blah... $10.00 each.

Start of FORM

Select color -

Select size -     (Note the extra charge for large)

Select fabric -     (Note the extra charge for silk)

Select tax for this order -     (Ontario model)

Input some words -

Pick some (or not).
Disco sucks
Dewey elected
Nerds rule

Quantity -     Enter Coupon code (optional - 10%) -

   

End of FORM

Rules of JS Use

  1. You first have to capture the JavaScript (JS). Click the link at the upper right of this page and it will display in your browser. It depends on your browser, but do a <select all> <copy> and <paste> it into your Word Processor (Wordpad works just fine).

    From your WP do a <save as> to put the JS where you want it. A good place is in the same folder as your order page. An important part of this save operation is to make sure you are saving the file in pure text format, and not some WP format with controls at the start of it. The main reason for not being able to read the JS file is that is was saved in some WP format.

  2. Assuming that you saved the JS as "sing.js" you add it to your HTML page by including these lines right after the <body>...

        <script type = "text/javascript"
                src  = "sing.js">
        </script>
    
  3. If you are going to use any of the quantity discount, amount, handling or shipping tables, you may make calls to build them in a separate JavaScript selection (after the above selection) in this manner...

        <script type="text/javascript">
          SetQD (q1, p1, q2, p2, ...);
          SetHN (q1, p1, q2, p2, ...);
          SetSH (q1, p1, q2, p2, ...);
        </script>
    
      where
        q1 = 1st quantity breakpoint
        p1 = amount after q1 breakpoint
        q2 = 2nd quantity breakpoint
        p2 = amount after q2 breakpoint
         etc.
    

    You may also set the weight of the item here, if you are going to use the internal USPS Priority shipping tables (it is probably the best place)...

        SetWT (3.5);  // ounces that a single item weighs
    
    Note: placing them in the onload event handler of the body can get you into trouble because some sites never finish loading because of errors on the page, or references to nonexistant images on other servers. This is the best/safest way.

    The tables may be as large as you want them to be, limited only by memory in the customer's computer (because that is where they are built).

  4. Modify the FORM output from the PayPal button factory. This is the hard part (but not that hard). See the listing of the HTML for this page for an example of how I did it.

And that is all there is to it. The JS is just a utility that you use and never have to mess with, and you get added features with your Single Item Purchase web page. WARNING - you cannot use many of these features in a shopping cart as coded. Please trust me in this!

Image: XHTML 1.1 certified! Image: CSS2 certified! Image: Multi-user accessibility! counter Version loads.

Contact me concerning this article at paypalhelper@aol.com. Mention "SIP" in your note.

Individual help starting at $25.00 for simple JS solutions.


Some links to help you with your shipping tables and charges...

* How to build zone/rate tables in JavaScript.
* USPS Zones, and Priority rates.
* UPS Zones.
* FedEx Zones.

These tables may also be used to construct shipping charts with the SetSH function. For example, you may not want to construct a complete shipping table for Europe, so you can approximate charges to those countries by building charge tables with the quantity-based shipping charge builder (SetSH).

I was a little surprised to discover that USPS was cheaper than UPS below the 3-9 pound area, depending on distance and UPS fuel charges. Perhaps the best approach is to calculate several different shipping options for the user, display them and let him take his pick.

The total surprise to me was that you could calculate zone tables for any shipper there is (they all supply this information), and support national or international - depends on how much time you want to spend to set up your tables. It can all be done client-side without the need for a server, or e-commerce solution. Remarkable! But, ya gots to know some JavaScript to do it, huh?

NOTE - you must really read these charts! In the case of UPS there are some zones (Hawaii, Alaska, and the Protectorates) that require special attention. The best solution is, probably, to create special zones for their ZIPs (9, 10, 11, etc) and enter them into your tables (both zone and charge.) Any other solution simply misleads people in these ZIP code areas. USPS is subsidized, and it may be cheaper to ship to those areas that way.