You are viewing limited content. For full access, please sign in.

Question

Question

Advance to next form tab using JavaScript

asked on July 19, 2019 Show version history

Hi all,

Just wondering if there's an easy way to do the above? Our client are looking to have a checkbox at the end of each form page to confirm they've checked the data on that page, and ideally want the form to advance to the next page automatically when the checkbox is checked.

I've tried using .click() on the next button to simulate a user clicking "Next" but it advances to a blank page - I'm guessing there must be some parameter/event that's not being fulfilled? This is what I have so far:

$(document).ready(function(){
  $('.checkbox input').on('change', function(){
     if ($('.checkbox input').prop('checked')) {
        $('.cf-next-btn').click();
     }
  });
});

Any ideas would be appreciated!

Thanks, Dan

0 0

Answer

SELECTED ANSWER
replied on July 19, 2019 Show version history

Triggering .click() on the next button should work and I actually do it quite often with my paginated forms, but you need a more specific selector.

Each page has its own "next" button, so the selector you used will activate all of them and cause the blank page when it activates the one on the last page.

Try the following:

$('.cf-page.active .cf-next-btn').click();
1 0
replied on July 19, 2019

Cheers Jason, works perfectly!

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.