I have this code. I have 4 CRED forms on one page all setup to submit by AJAX and have put the JS once on the page in the content template that contains references to all the forms.
However, the issue I have is that although they are all setup to post by AJAX, it's updating all the forms but then reloading the page (which I dont want)
I set up a test for this and composed my own script.
It's important not to get into a recursive loop when programmatically applying clicks to other submit buttons once an actual click has occurred on another button, and my solution for that is below, and depends on the event object being different depending on whether the click was real or programmatic.
I am wondering about what you expect to happen next, though, inasmuch as the form content is replaced by the ajax submission, including the submit buttons, so the event listeners are not attached to the updated buttons, so you can't submit them again and have the same thing happen. (I don't think there is a JS event available when the form has finished submitting via ajax to re-attach them.)
Thanks for your efforts on this. I will try your code in a moment. Must one thing to note. Adding my original JS directly in ONE of the forms makes it work without refresh. Having the JS code in the Content Template meant it didn't.
I was just adding multiple forms to a page and so my JS was in one of the forms, I'm not sure of the details of your setup to know how the Content Template is involved...