Redirect button after selection

I have two buttons (describing the type of delivery). After making a selection, I need to press another button to continue. Is there a way that I can proceed automatically after making a selection?

Here is my code before choosing:

<button type="button" class="button btn-delivery-method" data-delivery-method="s_method_free">
    <span class="btn-delivery-method__label">Select</span>
</button>

      

Here is my code after selection:

<button type="button" class="button btn-delivery-method delivery-method__selected" data-delivery-method="s_method_free">
    <span class="btn-delivery-method__label">Select</span>
</button>

      

Here is my third button:

<button type="button" class="button btn-large--alt" onclick="shippingMethod.save()">    
    Continue    
</button>

      

thank

+3


source to share


3 answers


You can add an onclick event to the first two buttons.



Btw what does the code do after clicking one of the first two buttons?

0


source


Bind the click event to the first button:

$(".button.btn-delivery-method").click(function() {

   // check if the delivery has been selected
   if($(this).hasClass("delivery-method__selected")) {
      // either call shippigMethod.save(); here

      //trigger the button click
      $(".button.btn-large--alt").trigger("click");
   }
});

      



This will only trigger the button when you select a delivery

if($(this).hasClass("delivery-method__selected")) {
     $(".button.btn-large--alt").trigger("click");
 }

      

0


source


It would be nice to have the Id of your second button to avoid conflicts with other buttons.

0


source







All Articles