1
<div class="buttons"> <a href="#" class="btn btnGreen"><span>Beta Signup</span></a> <span><em>or</em></span>
      <a onclick="test()" class="btn btnBlue"><span>Donate to Development</span></a> </div>

      <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="JZDSU6T647PL4">
      <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_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_US/i/scr/pixel.gif" width="1" height="1">
      </form>


  </div>

I want the action from the form to happen when i click on the donate to development button, how could i do this??? I want the imaging from the btn btnblue class but it does not transfer over to the form

CHouse95
  • 111
  • 8
  • what do you mean on `imaging from the btn btnblue class` and `it does not transfer`? – Gavriel Jan 29 '16 at 01:21
  • You can call the submit() function of the form element in your function test(), or you could create a new input element with type 'submit' which will automatically submit the form it's in when pressed, which is how it's usually done. – Mandera Jan 29 '16 at 01:24

3 Answers3

1

you need to create a function that submits the form via javascript. Eg.

<a onclick="submit()" class="btn btnBlue"><span>Donate to Development</span></a>

function submit() {
  var form = document.querySelector('form');
  if(whatever){
   form.submit();
  }
}
Shan Robertson
  • 2,742
  • 3
  • 25
  • 43
1
<a onclick="test()" class="btn btnBlue"><span>Donate to Development</span></a>
<script>
 function test() {
var form = document.querySelector('form'); if(whatever){ 
form.submit();
 } }
</script>

Create a JavaScript function

Gautam Jha
  • 1,445
  • 1
  • 15
  • 24
1

You don't need a function if you aren't going to do anything more than just submit the form.

<div class="buttons"> <a href="#" class="btn btnGreen"><span>Beta Signup</span></a> <span><em>or</em></span>
      <a onclick="document.getElementById('form1').submit(); return false;" class="btn btnBlue"><span>Donate to Development</span></a> </div>

      <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" id="form1">
      <input type="hidden" name="cmd" value="_s-xclick">
      <input type="hidden" name="hosted_button_id" value="JZDSU6T647PL4">
      <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_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_US/i/scr/pixel.gif" width="1" height="1">
      </form>


  </div>
Aaron
  • 511
  • 3
  • 25