Skip to content
Advertisement

Generalization of JQuery submit function

In my web application I have dozen of forms, of course each one with a different id. Then in my JavaScript file I wrote a custom handler for the submit event:

JavaScript

I want to avoid to write the above code for each form. As first step I can just wrap it in another function, something like this:

JavaScript

and then use:

JavaScript

but this is not a valid syntax. In any case I still need to “connect” each form to the custom function, writing two times its name.

Is there a way to match all the forms that have a specific prefix and connect all of them to my custom submit function passing both the form id and the event variable as above? Example of prefix:

JavaScript

Advertisement

Answer

JavaScript

will handle all forms on the page

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement