点击可选复选框时如何计算价格(使用贝宝支付表单)


How to calculate price when optional checkbox is clicked(using paypal payment form)

我构建了一个订单表单,用户可以在其中输入公司名称、姓氏、电子邮件和地址,以及价格为19.99美元的可选发货复选框。我下载了我的dreamweaver cs5程序的贝宝支付表单模块,该程序将表单转换为贝宝表单。

这个程序的好处是,当一个人点击"立即付款"按钮时,它会自动创建一个包含所有输入字段的mysql数据库。它还会在一个名为"PPPaymentForm"的文件夹中自动生成文件,然后我将其上传到我的网站根目录中,并为我提供一个后端,这样我就可以监控所有的支付交易。

因此,回到我最初的问题,我需要一些方法,这样,如果一个人决定点击设置为19.99美元的复选框,它将自动添加到名为"hdwppamount"的隐藏输入中设置的价格中,其中值设置为175.00美元。因此,如果点击发货选项,用户会点击"立即付款"按钮,并被重定向到贝宝支付页面,新计算的价格为194.99美元。

我不精通javascript或php,自己尝试了很多函数,但都没有成功。有人能帮我做这个吗?

谢谢

<form action="PPPaymentForm/PPPaymentForm.php" method="post" name="topchoiceform" id="topchoiceform">
  <input placeholder="Company Name" type="text" name="companyname" required>
  <input placeholder="First Name" type="text" name="firstname" required>
  <input placeholder="Last Name" type="text" name="lastname" required>
  <input placeholder="Email" type="email" name="email" required>
  <input placeholder="Address" type="text" name="address" required>
  <input type="checkbox" id="shipping" name='shipping' />$optional Shipping($19.99)
  <button name="submit" type="submit">Pay Now</button>
  <input type="hidden" name="hdwtablename" id="hdwtablename" value="1">
  <input type="hidden" name="hdwppproductname" id="hdwppproductname" value="Basic 175 Plan">
  <input type="hidden" name="hdwppamount" id="hdwppamount" value="175">
  <input type="hidden" name="hdwppcurrency" id="hdwppcurrency" value="USD">
  <input type="hidden" name="hdwpplanguage" id="hdwpplanguage" value="en_US">
  <input type="hidden" name="hdwok" id="hdwok" value="">
  <input type="hidden" name="hdwemail" id="hdwemail" value="email+gmail.com">
  <input type="hidden" name="hdwnook" id="hdwnook" value="http://">
  <input type="hidden" name="hdwactivation_email" id="hdwactivation_email" value="email">
</form>

首先,我们检测发货复选框何时更改,然后检查它是否处于选中状态。如果它处于选中状态,我们将运费添加到隐藏的文本框中。如果用户改变了对发货的想法,我们还需要重置该值,因此您需要一个基本的if ELSE条件。

试试这个:

$('#shipping').change(function(){
    var hdwppamount = Number($("#hdwppamount").val())
    var shippingcost = 19.99;
     if (this.checked) {
        $("#hdwppamount").val(hdwppamount+shippingcost)
     } else {
        $("#hdwppamount").val(hdwppamount-shippingcost)
     }
})

JSFiddle:https://jsfiddle.net/rdawkins/8qrm3mf1/14/