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
Release: 2024-12-01 11:39:13
Original
530 people have browsed it

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template