Skip to content
Advertisement

JavaScript function of form without click the button

Here is my completed code for doing function for the form of going to the PayPal payment gateway by javascript without clicking on the “BUY NOW” button. Just my problem is here, this going to opening a new window to do that, I want this function to do it on the same window. Please guide me on how can we fix it? Any help will be appreciated.

window.onload = function() {
   
  // u should put a name for your form
  document.forms['my_form'].submit();
}
<form target="PayPal" id="my_form" action="https://www.paypal.com/cgi-bin/webscr" method="post" style="margin:0;padding:0;">
  <input type="hidden" name="business" value="test@yahoo.com">
  <input type="hidden" name="cmd" value="_xclick">
  <input type="hidden" name="item_name" value="Membership">
  <input type="hidden" name="item_number" value="1 Month">
  <input type="hidden" name="amount" value="23">
  <input type="hidden" name="currency_code" value="USD">
  <input type="hidden" name="shipping" value="">
  <input type="hidden" name="shipping2" value="">
  <input type="hidden" name="handling" value="">
  <input type="hidden" name="return" value="https://test.com/Successful_Payment.php">
  <input type="hidden" name="cancel_return" value="">
  <input type="hidden" name="undefined_quantity" value="0">
  <input type="hidden" name="receiver_email" value="test@yahoo.com">
  <input type="hidden" name="no_shipping" value="1">
  <input type="hidden" name="no_note" value="0">
</form>
```

Advertisement

Answer

remove attribute target=”Paypal” from the form

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement