Alan Tingey Alan Tingey -4 years ago 115
HTML Question

Paypal Button with £0 Option

I have a PayPal form which has an three options £5, £3 & £0.

The button works if I choose either £5 or £3 but does not work with £0. Is there a way to capture when the "Pay" button is clicked and the option of £0 selected to redirect the user to a pre determined URL such as "bbc.co.uk"?

Any help on this would be appreciated.

Below is the form:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="CUP9TLQ96MR28">
<table>
<tr>
<td><input type="hidden" name="on0" value="str8RED"></td>
</tr>
<tr>
<td>
<select name="os0">
<option value="Premium ->">Premium -> £5.00 GBP</option>
<option value="Standard ->">Standard -> £3.00 GBP</option>
<option value="Basic ----->">Basic -----> £0.00 GBP</option>
</select>
<input type="hidden" name="currency_code" value="GBP">
<input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_paynow_SM.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</td>
</tr>
</table>



Answer Source

This should work. (JSFiddle)

<script>
function myFunction() {
  var sel= document.getElementById("os0");
  if (sel.options[sel.selectedIndex].value == 'Basic ----->') {
    window.location.replace("http://stackoverflow.com");
    return false;
  } else {
    document.getElementById("myForm").submit();
  }
</script>



<form id="myForm" onsubmit="event.preventDefault(); myFunction();">
  ...
  <select name="os0" id="os0">
    ...
  </select>
  ...
</form>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download