How to change to next form stage on enter

Created by Phil Kurth, Modified on Tue, 15 Aug 2023 at 07:52 AM by Phil Kurth

By default, hitting the enter key submits a form. If you need to modify this behaviour when using a multistage form, you may use the following snippet as a boilerplate.


jQuery(function($) {
  
  // Add your form key here
  const formKey = 'form_62d743d9eca45';
  
  $('.af-form input').on('keydown', function(e) {
    if (e.originalEvent.key === 'Enter') {
      e.preventDefault(); // Preventing the default action
      if (af.forms[formKey] && af.forms[formKey].$next_button) {
        af.forms[formKey].$next_button.click();
      }
      return false;
    }
  });
});

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 atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article