February 26, 2007

E-commerce > JavaScript for Minimum Purchase Quantities

javascript-qty-alert.gif

We had a problem at work with people ordering the wrong quantity from the Web site. Some items had volume pricing - the more you buy, the less you pay for each unit.

I tried changing the item description to make it more obvious, but no joy. People were still ordering a quantity of one unit for items that were priced for a quantity of 50 or 100 or more.

I decided to use JavaScript to trigger an alert message. But how to trigger it? There are various JavaScript OnLoad commands. It's often done with the <BODY> element.

For my purpose the easiest solution was to trigger the alert message using an OnLoad statement with an IMG tag. Each item has an extended description that can include images and HTML. So in the description I included an image tag for spacer.gif (a 1x1 pixel transparent GIF image). The image loads almost as soon as the page loads and triggers the alert.

Here's the code and a live example of the script:

<img src="http://www.lesjones.com/www/images/spacer.gif" onLoad="window.alert('You must buy a minimum of 100 units to qualify for this price level.');"></img>

Since adding this code a few weeks ago we haven't had any orders for the wrong quantity.

Posted by lesjones | TrackBack



Comments
Post a comment










Remember personal info?







Terms of Use