dongtuo1482 2016-04-05 17:09
浏览 82
已采纳

单击可选复选框时如何计算价格(使用paypal支付表格)[复制]

This question is an exact duplicate of:

I have built an order form in which the user would enter in a company name, last name, email and an address and an optional checkbox for shipping priced at $19.99. I downloaded the paypal payment form module for my dreamweaver cs5 program which converts the form into a paypal form.

The nice thing about this program is that it automatically creates a mysql database with all the input fields when a person clicks the "pay now" button It also generates the files automatically in a folder called "PPPaymentForm" which i then upload in the root of my site and gives me a backend as well so i can monitor all the payment transactions.

So back to my original issue, i need some way so that if a person decides to click the checkbox which is set at $19.99, that it will automatically add to the price which is set in an hidden input named "hdwppamount" where the value is set to $175.00. So therefor if the shipping option is clicked, the person would click the "Pay Now" button and would be redirected to the paypal payment page, with the new calculated price at $194.99.

I am not proficient with javascript or php, and tried many functions myself but nothing worked. Could someone help me with this please?

Thank You

<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>
</div>
  • 写回答

1条回答 默认 最新

  • douzhan3900 2016-04-05 18:58
    关注

    First, we detect when the shipping checkbox is changed, then we check to see if it is in a checked state. If it is in a checked state, we add the shipping cost to the hidden text box. We also need to reset the value if the user changes their mind about shipping so you need a basic IF ELSE condition on it.

    Try this:

    $('#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/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘