1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

On submit add something to a form

Discussion in 'JavaScript' started by qwikad.com, Mar 20, 2019.

  1. #1
    Using javascript (or jQuery) how can I add the word "Success" to "&resultCode=" on form submit? So the link should look like this after submit:

    ht tps://somesite.com/payment.php?Done&sellerOrderId=<?php echo $item_number; ?>&resultCode=Success

    
    <form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="myForm">
    
    <input type="hidden" name="return" value="https://somesite.com/payment.php?Done&sellerOrderId=<?php echo $item_number; ?>&resultCode=">
    
    <button type="submit" name="submit"></button>
    </form>
    
    Code (markup):
     
    qwikad.com, Mar 20, 2019 IP
  2. Tom-Brown

    Tom-Brown Well-Known Member

    Messages:
    105
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #2
    I think I understand what youre wanting. Heres how I would do it with jquery. If you want it in normal javascript just say.

    
    <div class="form-holder">
                <form id="paypal-form" action="https://www.paypal.com/cgi-bin/webscr" method="post" id="myForm">
    
                <input type="hidden" name="return" value="https://somesite.com/payment.php?Done&sellerOrderId=<?PHP echo $item_number; ?>&resultCode=">
    
                <button type="submit" name="submit">Submit</button>
    
                </form>
    </div>
    
    HTML:
    
            jQuery(document).ready(function(){
    
               jQuery("#paypal-form").submit(function(event){
                 // find input
                 // could use id instead of this method
                 var returnInput = jQuery(this).find('input[name=return]');
    
                 // check we have an input
                 if(returnInput && returnInput.val().substr(-7) !== 'Success'){
                   returnInput.val(returnInput.val() + 'Success');
                 }
    
    
                 return true;
               });
    
             });
    
    Code (JavaScript):
     
    Tom-Brown, Mar 21, 2019 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #3
    If it's always going to be "success" when the form submits, why isn't it just there in your value? this isn't JavaScript's job (it could in fact screw things up -- what about scripting off/disabled users?) nor is it really even something that belongs client-side!

    Much less why would you even set such a value since it's success even if the paypal side fails. First line of the return from PP should be what you're using, though as always if the message CLAIMS success, still verify with an IPN listener.

    https://github.com/paypal/ipn-code-samples/tree/master/php
     
    Last edited: Apr 5, 2019
    deathshadow, Apr 5, 2019 IP