JavaScript listens for form form submission

the landlord has encountered a problem. The project is relatively old, and most of the code uses inline js to operate.
but encountered a problem about form submission, involving more pages, not easy to change!
questions
forms interact with each other using inline js onclick= "submit ()", and the code uses

document.form1.submit(); // 

how can I use js to listen for the submit event of this form form in such a situation? Or other solutions!
Thank you

Mar.17,2021

try this?
onclick= "fu ()"; function fu () {your code.; submit ()}


according to the standard form.submit is the last means of submission, there is no event capture in the middle, the normal method is
1, the button responds to the button operation, call form.submit in the function (example below)
2, add the onsubmit, button for form to use input:submit to submit the form (example)
abnormal method, overload the submit method of form, call the click method of the submit button to submit. (example below)

idesubmit" rel=" nofollow noreferrer "> http://js.do/code/overridesubmit

harvest:
Native methods can also be overridden!

the code is as follows:

<form name='form1' id=form1 method='post' action='http://www.baidu.com'> <input type=text name='n' value=1 > <input type=button onclick='submit()' name='n' value='test'> <input style='display:none' type=submit id='post'> </form> <script> form1.submit=function(){let oldsubmit=this.submit;alert(oldsubmit);post.click()} </script>

<form name='form2' id=form1 method='post' action='http://www.baidu.com'> <input type=text name='n' value=1 > <input type=button onclick='btnclick()' name='n' value='test'> </form> <script> function btnclick(){ alert('do something'); form2.submit(); } </script>

Menu