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!