Home >Web Front-end >JS Tutorial >How Can a Button Prevent Unwanted Form Submission Without JavaScript?

How Can a Button Prevent Unwanted Form Submission Without JavaScript?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-01 11:39:13620browse

How Can a Button Prevent Unwanted Form Submission Without JavaScript?

Can a Button Avoid Submitting a Form?

In a form containing two buttons, a "Cancel Changes" button and a "Submit" button, both styled using jQuery UI, the former unexpectedly submits the form. Despite lacking the "type=submit" attribute, it causes form submission.

While a JavaScript solution can prevent this using event handling, is there a way to disable form submission without relying on JavaScript?

Answer:

The default "type" attribute for button elements is "submit." Setting the attribute to "button" prevents the button from submitting the form.

<button type="button">Cancel Changes</button>

As stated in the HTML Standard, buttons with the "type=button" attribute "do nothing."

The above is the detailed content of How Can a Button Prevent Unwanted Form Submission Without JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn