将优惠券代码应用于PayPal表单中的下拉菜单

时间:2019-03-18 20:12:49

标签: javascript html5 forms

从下拉列表中读取下拉值并应用优惠券代码。优惠券代码检查功能效果很好。下拉列表和数量将非常有用。如果不了解如何在下拉菜单中使用此功能,就可以使用通用PayPal格式的单个订单项正常工作。谢谢您的帮助。

    var discnt = 0; // no default percent discount
var coupons = new Array( // place to put coupon codes
    "group10", // 1st coupon value - comma seperated
    "group20", // 2nd coupon value - add all you want
    // 3rd coupon value
);
var coupdc = new Array( // place to put discounts for coupon vals
    10,
    20,
);
var coupval = "(blanket)"; // what user entered as coupon code
function ChkCoup() { // check user coupon entry
    var i;
    discnt = 0; // assume the worst
    for (i = 0; i < coupons.length; i++) {
        if (coupval == coupons[i]) {
            discnt = coupdc[i]; // remember the discount amt
            alert("Valid coupon number! \n\n" + discnt +
                "% discount now in effect.");
            return;
        }
    }
    alert("'" + coupval + "' is not a valid code!");
}
function Dollar(val) { // force to valid dollar amount
    var str, pos, rnd = 0;
    if (val < .995) rnd = 1; // for old Netscape browsers
    str = escape(val * 1.0 + 0.005001 + rnd); // float, round, escape
    pos = str.indexOf(".");
    if (pos > 0) str = str.substring(rnd, pos + 3);
    return str;
}
function ReadForm(obj1) { // apply the discount
    var amt, des;
    amt = obj1.baseamt.value * 1.0; // base amount
    des = obj1.basedes.value; // base description
    if (discnt > 0) { // only if discount is active
        amt = Dollar(amt - (amt * discnt / 100.0));
        des = des + ", " + discnt + "% dis, COUP = " + coupval;
    }
    obj1.amount.value = Dollar(amt);
    obj1.item_name.value = des;
}
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="this.target = 'paypal';
return ReadForm (this);">
  <input type="hidden" name="cmd" value="_xclick">
  <input type="hidden" name="business" value="youremail@email.com">
  <input type="hidden" name="lc" value="US">
  <input type="hidden" name="button_subtype" value="services">
  <input type="hidden" name="no_note" value="0">
  <input type="hidden" name="currency_code" value="USD">
  <input type="hidden" name="bn" value="PP-BuyNowBF:btn_paynowCC_LG.gif:NonHostedGuest">
  <table class="coupon-form-tables">
   <tbody align="left">
    <tr>
     <td>
      <input type="hidden" name="on0" value="Courses - Individual">
      <p class="price-card">
       Courses - Individual
      </p>
     </td>
    </tr>
    <tr>
     <td>
      <select name="os0">
       <option value="CPR Individual">
        CPR Individual $60.00 USD
       </option>
       <option value="EMT Individual">
        EMT Individual $650.00 USD
       </option>
       <option value="EMR Individual">
        EMR Individual $450.00 USD
       </option>
       <option value="First Aid Individual">
        First Aid Individual $160.00 USD
       </option>
       <option value="ACLS Individual">
        ACLS Individual $160.00 USD
       </option>
       <option value="PALS Individual">
        PALS Individual $160.00 USD
       </option>
       <option value="Active Shooter w/o Celox™">
        Active Shooter w/o Celox™ $200.00 USD
       </option>
       <option value="Active Shooter w/ Celox™">
        Active Shooter w/ Celox™ $225.00 USD
       </option>
      </select>
     </td>
    </tr>
    <tr>
     <td>
      <select name="quantity">
       <option value="1">
        1
       </option>
       <option value="2">
        2
       </option>
       <option value="3">
        3
       </option>
      </select>
     </td>
    </tr>
   </tbody>
  </table>
  <p class="price-card">
   Enter Coupon Code To Access Group Pricing
  </p>
  <input type="text" size="10" name="coupcode">
  <input type="button" value="Check It" onclick="coupval = this.form.coupcode.value;
ChkCoup();">
  <input type="hidden" name="option_selecct0" value="CPR Individual">
  <input type="hidden" name="option_amount0" value="60.00">
  <input type="hidden" name="option_select1" value="EMT Individual">
  <input type="hidden" name="option_amount1" value="650.00">
  <input type="hidden" name="option_select2" value="EMR Individual">
  <input type="hidden" name="option_amount2" value="450.00">
  <input type="hidden" name="option_select3" value="First Aid Individual">
  <input type="hidden" name="option_amount3" value="160.00">
  <input type="hidden" name="option_select4" value="ACLS Individual">
  <input type="hidden" name="option_amount4" value="160.00">
  <input type="hidden" name="option_select5" value="PALS Individual">
  <input type="hidden" name="option_amount5" value="160.00">
  <input type="hidden" name="option_select6" value="Active Shooter w/o Celox™">
  <input type="hidden" name="option_amount6" value="200.00">
  <input type="hidden" name="option_select7" value="Active Shooter w/ Celox™">
  <input type="hidden" name="option_amount7" value="225.00">
  <input type="hidden" name="option_index" value="0">
  <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
  <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
 </form>

0 个答案:

没有答案