paypal表单问题的单选按钮选择

时间:2016-04-19 17:57:31

标签: javascript html paypal calculated-field

需要你的帮助

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

我想要发生的是,如果一个人选择了第一个收音机盒(" $ 19.99运输 - DATABASE SENT ON CD ROM"),那么19.99会自动添加到" hdwppamount&# 34;金额设定为175美元,因此当该人按下"现在支付"时,它将在paypal页面上总计$ 194.99。

如果该人选择了第二个选项("免费送货 - 数据库通过电子邮件发送"),那么当然没有任何价值被添加到" hdwppamount"金额和175美元将是paypal页面的总数。

现在,如果用户选择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>

1 个答案:

答案 0 :(得分:0)

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

我将输入字段hdwppamount从隐藏更改为片段中的文本以清除行为。

&#13;
&#13;
$(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');
});
&#13;
<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>
&#13;
&#13;
&#13;