How to change a form that does not have an action attribute (or method attribute)

It is not uncommon to stumble upon form code like this that does not have an action or method attribute visible in the HTML code.

<form id="subscription">
<button type="submit" >Submit</button>

Surprisingly, when you submit the form, the form gets submitted and you will see a message to that effect. How does this work?

# Handling forms using JavaScript

The trick is to use JavaScript to capture the form submission event. The JavaScript code then collects the form data and sends the form data to the server. An apropriate message is displayed to the user.

Here is some sample code that shows how this can be done:

Using Javascript to handle form submission has many benefits. You can handle different cases dynamically. For example, you can validate the form data and show error message, hide the form and show a progress message instead. This is the reason why many web developers prefer to handle forms entirely using JavaScript.

# Modifying the form behavior

If you could find the Javascript code that handles the form, then making changes will be easier. If you have access to the source code, just try searching using the id of the form. In case the script displays any error message, search using the message text.

Remember that the script could be in another file. Usually all Javascript code will be divided into modules and added to the HTML file using <script > tag. So you will have to search the whole source code. Searching multiple files is not a dauting task if you are using a good editor like Visual Studio code or Sublime text.