The problem is that the form is submitted by default.
You cannot cancel the attribute of the action form and add it later using JavaScript, because the browser will use the current page as action , and the form can still be submitted.
In addition, removing the submit button does not help, since the form can still be submitted using the enter key.
But I obey you (pun intended!) This evil idea:
<form action="#"> .... </form>
this makes the form almost unbeatable at first, since the goal of the submission is the current page.
Then you must set the correct action attribute using JavaScript.
I canโt think of any reason why this will not work reliably in browsers, except that trying to send it will force the browser to go to the top of the page due to the hash # .
source share