I'm trying to offer a discount based on the purchase amount of the buyer using a paypal Add to Cart form. Basically I'm giving out for discount codes Disc1, Disc2, Disc3, Disc4, which will discount $5, $10, $20, $50. But each can work only if the purchase amount exceeds the $25, $50, $100, $250 respectively.
I'm trying to do this by calling a Javascript file which will apply the discount if the minimum price conditions are met.
The PROBLEM is that the form is for multiple items. So the variable for "amount" is not there, but there's different amounts for each option, so option_amount0, option_amount1, option_amount2.... etc. I can make the code work if there was one "amount", but not like here with multiple items/prices.
The HTML code looks like this:
<head>
<script language="JavaScript" type="text/javascript" src="coupon.js"></script>
</head>
<form target="_blank" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="Products">
<input type="hidden" name="button_subtype" value="">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="undefined_quantity" value="1">
<input type="hidden" name="rm" value="1">
<input type="hidden" name="return" value="www.website.com">
<input type="hidden" name="cancel_return" value="www.website.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="tax_rate" value="0.000">
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="add" value="1">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHosted">
<table>
<tr><td><br /><h4>
<center><input type="hidden" name="on0" value="Products">Choose a Product</center></h4></td></tr><tr><td><center>
<select name="os0" style="width: 230px"></center>
<option value="item1">Product 1 : $15</option>
<option value="item2">Product 2 : $25</option>
<option value="item3">Product 3 : $75</option>
<option value="item4">Product 4 : $150</option>
<option value="item5">Product 5 : $300</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="option_select0" value="item1">
<input type="hidden" name="option_amount0" value="15.00">
<input type="hidden" name="option_select1" value="item2">
<input type="hidden" name="option_amount1" value="25.00">
<input type="hidden" name="option_select2" value="item3">
<input type="hidden" name="option_amount2" value="75.00">
<input type="hidden" name="option_select3" value="item4">
<input type="hidden" name="option_amount3" value="150.00">
<input type="hidden" name="option_select4" value="item4">
<input type="hidden" name="option_amount4" value="300.00">
<input type="hidden" name="option_index" value="0">
<input type="hidden" name="discount_amount">
<br />
<!-- Enter Coupon -->
<center>Coupon Code:</span> <br />
<input type="text" name="text1" /> </center>
<br />
<!-- End Coupon -->
<input type="image" src="images/btn_cart.gif" border="0" onclick=CalculateOrder(this.form) name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="images/btn_cart.gif" width="1" height="1">
</form>
The Javascript file is:
var coup1="Disc1";
var coup2="Disc2";
var coup3="Disc3";
var coup4="Disc4";
function CalculateOrder(form) {
if (form.text1.value == coup1 && ((form.option_amount.value>=25)))
{
form.discount_amount.value = "5";
}
if (form.text1.value == coup2 && ((form.option_amount.value>=50)))
{
form.discount_amount.value = "10";
}
if (form.text1.value == coup3 && ((form.option_amount.value>=100)))
{
form.discount_amount.value = "20";
}
if (form.text1.value == coup4) && ((form.option_amount.value>=250)))
{
form.discount_amount.value = "50";
}
}
How can I make the script account for the option_amount from the HTML form? Any help would be greatly appreciated!