iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
✨

How to prevent buttons inside a form tag from triggering submission

に公開

When I was trying to integrate two functions into one and wrapped a table tag with a form tag, clicking a button inside the table that performs Ajax communication started triggering a form submission.

I considered not using the form tag and sending the values separately via JavaScript, but I found a solution after reading the following article.

https://qiita.com/t_oginogin/items/b682f664ce8244a7c2bd

By default, the button tag has type: 'submit'.
Therefore, if you don't specify anything, clicking it will submit the form.

According to this reference, there is also a way to match the id attribute of the form tag with the form attribute of the button tag.
http://www.htmq.com/html5/button.shtml

The following article also solves a similar problem.

https://zenn.dev/phi/articles/form-submit-button-type-default

Discussion