【问题标题】:Radio button selection for paypal form issue贝宝表单问题的单选按钮选择
【发布时间】:2016-08-12 01:58:25
【问题描述】:

需要你的帮助

所以我有一个贝宝表单,它也有两个单选按钮。一个有运费,一个没有。这是实际表格的链接 http://www.topchoicedata.com/test.php

我想要发生的是,如果一个人选择了第一个单选框(“$19.99 Shipping – DATABASE SENT ON CD ROM”),那么 19.99 将自动添加到设置为 $175 的“hdwppamount”金额中,所以当该人按下“立即付款”时,将在贝宝页面上总共赚到 194.99 美元。

如果该人改为选择第二个选项(“免费送货 - 通过电子邮件发送数据库”),那么当然不会向“hdwppamount”金额添加任何价值,并且 175 美元将是贝宝页面的总额。

现在,如果人们选择 on 或其他选项,代码确实可以工作,然后不会在决定他们选择哪一个的单选按钮之间交替。所以它有点问题,因为如果我选择第一个选项,然后决定第二个选项,依此类推,我要么得到一个错误页面,要么如果我确实选择了免费选项,19.99 仍然会被添加。

我需要这样,如果选择第一个选项,则添加 19.99,如果选择第二个选项,则不添加任何内容。

任何帮助将不胜感激。

<!--------------------HTML Form---------------------_

  <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="first_name" required>
    <input placeholder="Last Name" type="text" name="last_name" required>
    <input placeholder="Email" type="email" name="email" id="email" required>
    <input placeholder="Address" type="text" name="address1" required>

    <input name="shipping" class="shipping" type="radio" id="shipping" checked/>
    <label class="shippingcheck">$19.99 Shipping – DATABASE SENT ON CD ROM </label>
     <br>
    <input name="shipping" class="shipping" type="radio" id="noshipping"/>
    <label class="shippingcheck">FREE SHIPPING – DATABASE SENT VIA EMAIL</label>

    <br>
    <button name="submit" type="submit" id="submit">Pay Now</button>



    <!-------------Paypal Part------------->
    <input type="hidden" name="hdwtablename" id="hdwtablename" value="1">
    <input type="hidden" name="hdwppproductname" id="hdwppproductname" value="Basic Plan 175">
    <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="http://www.topchoicedata.com/paymentmadethanks.php">
    <input type="hidden" name="hdwemail" id="hdwemail" value="mauriceflopez+gmail.com">
    <input type="hidden" name="hdwnook" id="hdwnook" value="http://">
    <input type="hidden" name="hdwactivation_email" id="hdwactivation_email" value="email">
    <input type="hidden" name="plan" id="plan" value="$175">
    <input type="hidden" name="shippingchoosen" id="shippingchoosen" value="">
    <input type="hidden" name="shippingnumber" id="shippingnumber" value="">
  </form>

PHP

<script>

$('#shipping').change(function(){

    var hdwppamount = Number($("#hdwppamount").val())

    var shippingcost = 19.99;



     if (this.checked) {

        $("#hdwppamount").val(hdwppamount+shippingcost)

     } else {

        $("#hdwppamount").val(hdwppamount-shippingcost)

     }

})

</script>

【问题讨论】:

  • 为了安全起见,您可以尝试 $("#hdwppamount").val(+hdwppamount + +shippingcost)
  • 您在上面标记为 PHP 的实际上是 JavaScript。我在这里删除了 php 标记,因为它无关紧要...

标签: javascript html paypal calculated-field


【解决方案1】:

使用收音机,您一次只能检查其中一个。这意味着您必须测试在指定时刻检查哪一个(即:更改事件)。

我将输入字段 hdwppamount 从隐藏更改为 sn-p 中的文本以明确行为。

$(function () {
  $('#shipping, #noshipping').on('change', function(){
    var hdwppamount = Number($("#hdwppamount").val());
    var shippingcost = 19.99;
    if (this.id == 'noshipping') { // shipping unchecked
      $("#hdwppamount").val(hdwppamount-shippingcost);
    } else { // shipping checked
      $("#hdwppamount").val(hdwppamount+shippingcost);
    }
  });
  // initialize the field with the correct value
  $("#hdwppamount").val('194.99');
});
<script src="https://code.jquery.com/jquery-1.12.1.min.js"></script>

<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="first_name" required>
    <input placeholder="Last Name" type="text" name="last_name" required>
    <input placeholder="Email" type="email" name="email" id="email" required>
    <input placeholder="Address" type="text" name="address1" required>

    <input name="shipping" class="shipping" type="radio" id="shipping" checked/>
    <label class="shippingcheck">$19.99 Shipping – DATABASE SENT ON CD ROM </label>
    <br>
    <input name="shipping" class="shipping" type="radio" id="noshipping" />
    <label class="shippingcheck">FREE SHIPPING – DATABASE SENT VIA EMAIL</label>

    <br>
    <button name="submit" type="submit" id="submit">Pay Now</button>



    <!-------------Paypal Part------------->
    <input type="hidden" name="hdwtablename" id="hdwtablename" value="1">
    <input type="hidden" name="hdwppproductname" id="hdwppproductname" value="Basic Plan 175">
    <input type="text" 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="http://www.topchoicedata.com/paymentmadethanks.php">
    <input type="hidden" name="hdwemail" id="hdwemail" value="mauriceflopez+gmail.com">
    <input type="hidden" name="hdwnook" id="hdwnook" value="http://">
    <input type="hidden" name="hdwactivation_email" id="hdwactivation_email" value="email">
    <input type="hidden" name="plan" id="plan" value="$175">
    <input type="hidden" name="shippingchoosen" id="shippingchoosen" value="">
    <input type="hidden" name="shippingnumber" id="shippingnumber" value="">
</form>

【讨论】:

  • 工作就像一个魅力!谢谢!
猜你喜欢
  • 2015-12-25
  • 2017-09-05
  • 1970-01-01
  • 2012-12-09
  • 1970-01-01
  • 2014-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多