javascript - Radio button selection for paypal form issue -
need help
so have paypal form has 2 radio buttons. 1 shipping value, , 1 without. here link actual form http://www.topchoicedata.com/test.php
what want happen if person selected first radio box("$19.99 shipping – database sent on cd rom"), 19.99 automatically added "hdwppamount" amount set @ $175, when person press's "pay now", make grand total of $194.99 on paypal page.
and if person selected second option instead("free shipping – database sent via email") instead, of course no value added "hdwppamount" amount , $175 total paypal page.
now code work if person chooses on or other options, , not alternate between radio buttons deciding 1 choose. kind of buggy because if choose first option, decided second option, , on , forth alternating, either error page or if did choose free option, 19.99 still gets added.
i need if first option chosen, 19.99 gets added, , if second option chosen, nothing added.
any appreciated.
<!--------------------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>
with radio may have 1 of them checked @ time. means have test 1 checked in specified moment (i.e.: change event).
i changed input field hdwppamount hidden text in snippet make clear behaviour.
$(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 field 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>
Comments
Post a Comment