MJ
asked on
Delay Form Submission without touching existing code?
I need some JS to execute completely before a form submits. The issue is the form submission truncates the JS code executing. I' m trying to figure out if I can delay a form submission without directly adding code to the form line.
Thanks!
P.S. I'm using Adobe's DTM -event based rule but I don't think that will matter in this case.
<form action="/responsive/letsgetstarted.html?prod=easy_checking" method="post">
The code would have to be added independently of any page mark-up so it would have to be standalone functionality. There is only one form on this page. I'd prefer JS answer to a jQuery solution.Thanks!
P.S. I'm using Adobe's DTM -event based rule but I don't think that will matter in this case.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm adding this code at page bottom and I tried DOM Ready but I still get the following error:
Uncaught TypeError: Cannot read property 'addEventListener' of undefined
Not sure why?
Uncaught TypeError: Cannot read property 'addEventListener' of undefined
Not sure why?
Hi mate,
My idea is to put that Javascript you need to execute inside this event, or call it from this event handler.
As long as your code is synchronous, the submission will only take place after it's finished.
On the other hand, if you're doing ajax calls, then it gets a bit more complex.
Btw, simply delaying the submission time is a very bad option. Different clients will take different times to complete, eventually breaking the logic or unnecessarily delaying the submission.
Let me know,
Alex
My idea is to put that Javascript you need to execute inside this event, or call it from this event handler.
As long as your code is synchronous, the submission will only take place after it's finished.
On the other hand, if you're doing ajax calls, then it gets a bit more complex.
Btw, simply delaying the submission time is a very bad option. Different clients will take different times to complete, eventually breaking the logic or unnecessarily delaying the submission.
Let me know,
Alex
ASKER
Thanks!
ASKER
I'm not following your example completely? Am I supposed to do some type of settimeout in the function before returning true or just have all my code I want to run in myFunction and then return true afterwards?