form.dashboard-form
in a DOMContentLoaded
event listener.form.addEventListener("submit")
to run your custom function on submit, optionally using event.preventDefault()
based on whether you want to override Webflow’s default behavior.To assign a custom JavaScript function to a specific Webflow form with the class "dashboard-form", you need to wait for the DOM to load and then add your function to the appropriate form event.
"dashboard-form"
in Webflow Designer.<form>
element, so the class should be applied directly to that <form>
element, not just a wrapper.<body>
under Page Settings > Before tag, or through Page Custom Code.
document.addEventListener("DOMContentLoaded", function () { const form = document.querySelector("form.dashboard-form"); if (form) { form.addEventListener("submit", function (event) { event.preventDefault(); // Optional: prevent actual submission myCustomFunction(form); }); }});
myCustomFunction
anywhere above or within the same script tag.function myCustomFunction(formElement) { // Your custom logic, e.g., data parsing, validation, API calls, etc. console.log("Form submitted:", formElement);}
w-form
Wrapperw-form
to the outer container, and uses the form
tag inside it.querySelector("form.dashboard-form")
if that class is applied directly to the form
element.event.preventDefault()
.event.preventDefault()
.To assign a function to a Webflow form with class "dashboard-form"
, use document.querySelector("form.dashboard-form")
inside a DOMContentLoaded
event, and attach your function using addEventListener("submit")
. This ensures the script runs only when the form exists and is fully loaded.