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):
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):
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