2016-04-19 7 views
1

brauchen Ihre HilfeOptionsfeld Auswahl für paypal Form Ausgabe

Also ich ein PayPal-Form haben, die auch zwei Radioknöpfe hat. Eins mit einem Versandwert und eins ohne. Hier ist der Link zu der eigentlichen Form http://www.topchoicedata.com/test.php

Was will ich zufällig ist, dass, wenn eine Person die erste Radio-Box ausgewählt („$ 19.99 Versand - Datenbank gesendet auf CD-ROM“), dann würde 19.99 automatisch auf die hinzugefügt werden "hdwppamount" Betrag, der auf $ 175 gesetzt wird, also wenn die Person "jetzt zahlen" drückt, wird es eine Gesamtsumme von $ 194.99 auf der paypal Seite bilden.

Und wenn die Person stattdessen die zweite Option ("KOSTENLOSER VERSAND - DATENBANK SENT VIA EMAIL") wählte, dann wird natürlich kein Wert zum "hdwppamount" Betrag hinzugefügt und $ 175 wäre die Summe für die Paypal Seite.

Jetzt funktioniert der Code, wenn die Person wählt auf oder die anderen Optionen, und dann nicht zwischen den Radio-Buttons abwechselnd entscheiden, welche sie wählen. Also seine Art von Buggy, denn wenn ich die erste Option wähle, dann die zweite Option, und so weiter und so fort wechsle, bekomme ich entweder eine Fehlerseite oder wenn ich die freie Option gewählt habe, wird der 19.99 trotzdem hinzugefügt.

Ich brauche so, dass, wenn die erste Option gewählt wird, dann der 19.99 hinzugefügt wird, und wenn die zweite Option gewählt wird, dann wird nichts hinzugefügt.

Jede Hilfe wäre willkommen.

<!--------------------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> 
+0

Sie könnten sicher versuchen $ ("# hdwppamount") zu tun. Val (+ hdwppamount + + versandkosten) – user2278120

+0

zu sein, was Sie markiert haben, wie oben PHP JavaScript ist eigentlich. Ich habe das _php_ Tag hier entfernt, weil es irrelevant ist ... – War10ck

Antwort

0

Mit Radio Sie nur einer von ihnen kann zu einem Zeitpunkt überprüft. Dies bedeutet, dass Sie testen müssen, welche zu einem bestimmten Zeitpunkt überprüft wird (z. B. Ereignis ändern).

Ich habe das Eingabefeld hdwppamount von versteckt zu Text im Snippet geändert, um das Verhalten zu verdeutlichen.

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

+0

Arbeitete wie ein Charme! Vielen Dank! –

Verwandte Themen