How to scroll to top of form when changing pages

Created by Phil Kurth, Modified on Sat, 26 Aug, 2023 at 7:04 AM by Phil Kurth

If you have a very long multi page form, you might choose to force the browser scroll position back to the top of the form on page change. You may do so using the following JavaScript snippet: 


jQuery(function ($) {
  acf.addAction('af/form/page_changed', function (page, previousPage, form) {

    const formId = '#' + form.key;
    
    $('html, body').animate({
      scrollTop: $(formId).offset().top
    }, 'slow');

  });
});

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article