Radio button triggered actions in submit form

769 Views Asked by At

I've customized my form, it's a regular order form that has 2 payment options right before the buy now button. I need to have the data going to autoresponder regardless of the payment option chosen...when they choose option 1 (cash), the form will redirect them to the thankyou page...but now that I have 2 radio buttons, how do I separate these events? How do I make them see the thankyou page if they choose option 1 - and redirect them to paypal if they choose the option 2?

<div class="gt-box">
  <div class="gt-labelpos">
    <label class="gt-label" id="500">How You Pay Mister?</label>
  </div>

  <div class="gt-inputpos">
    <div class="clrB">
      <input name="custom_payme" type="radio" class="gt-req gt-valid__required"
        checked="checked" value="cash"></input>
      <span class="gt-text">Ca$h</span>
    </div>
    <div class="clrB">
      <input name="custom_payme" type="radio" class="gt-req gt-valid__required"
        value="PayPal"></input>
      <span class="gt-text">PayPal</span>
    </div>
  </div>
  <em class="clearfix clearer"></em>
</div>
2

There are 2 best solutions below

4
topless On

On you server side when you receive your form's data, you can check the value of the radio button and according to that redirect respectively.

2
topless On

Another approach which will help you prevent redirects is on submit button click to evaluate your radio value and redirect from there. You Javascript code would look something like this

$('.submit-btn').click = function(e) {
  e.preventDefault();
  if ($('.custom_payme').val() === 'cash') {
    $.post("Your post url for cash", form_data);
  }
  else {
    $.post("Your post url for Paypal", form_data);
  };
};