贝宝表单问题的单选按钮选择

Radio button selection for paypal form issue

本文关键字:单选按钮 选择 问题 表单      更新时间:2023-09-26

需要您的帮助

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

我想做的是,如果一个人选择了第一个单选框("19.99美元运费-数据库发送在CD ROM上"),那么19.99将自动添加到"hdwppamount"金额中,该金额设置为175美元,因此当该人按下"立即付款"时,它将在贝宝页面上总共赚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从隐藏改为文本,以明确行为。

$(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>