Is it possible to implement a local JavaScript call upon submission of a form in Webflow?

Published on
September 22, 2023

Yes, it is possible to implement a local JavaScript call upon submission of a form in Webflow. Here is a step-by-step guide on how to achieve this:

  1. Open the Webflow Designer and navigate to the page containing your form.
  2. Select the form element, either by clicking on it in the Navigator or directly on the canvas.
  3. In the right-hand sidebar, click on the "Settings" tab.
  4. Scroll down to the "Form" section and click on the "Add Action" button.
  5. Choose the "Run Javascript" action from the list of available actions.
  6. In the code editor that appears, you can write your custom JavaScript code that will be executed upon form submission.
  7. Access the form inputs and values using standard JavaScript DOM manipulation methods like document.querySelector() or document.getElementById().
  8. Perform any desired operations using the form data, such as making an API call, sending an email, or updating a database.
  9. Save your changes and republish your site for the changes to take effect.

That's it! Now, whenever a user submits the form on your Webflow site, your custom JavaScript code will be executed.

Please note that if you're using external JavaScript files, make sure to include them in your Webflow project by going to the project settings and adding them under the "Custom Code" section.

Example Code:

document.querySelector('#myForm').addEventListener('submit', function(event) {  // Prevent the default form submission behavior  event.preventDefault();  // Get the form inputs and values  var name = document.querySelector('#nameInput').value;  var email = document.querySelector('#emailInput').value;  // Perform desired operations with the form data  console.log('Form submitted!');  console.log('Name: ', name);  console.log('Email: ', email);});

Note:
The example code above listens for the "submit" event on the form with the ID "myForm" and retrieves the values of the "nameInput" and "emailInput" form fields. It then logs the form data to the browser console.

Additional questions:

  1. How do I add custom JavaScript code to my Webflow form?
  2. Can I integrate a third-party API with my Webflow form using JavaScript?
  3. What other actions can I add to a form submission in Webflow?