How to add an HTML form action, after preventing the form's default behavior?

My HTML form’s opener tag is:

<form dir="rtl" lang="he" action="/backend/behavior.php" method="POST">

I prevent the default behavior of this form so action="/backend/behavior.php" method="POST" becomes ineffective as-is.
What could I use instead it, in my JavaScript file (where the default behavior is prevented)?

This depends on what you want to achieve.

You can user submit() to just do the same as the form itself would do or you can fetch the form data and send it through an Ajax call.

1 Like