Closed Bug 389431 Opened 18 years ago Closed 18 years ago

HTML <button> tag submits a form.

Categories

(Toolkit :: Form Manager, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 97829

People

(Reporter: mike.elmore, Unassigned)

Details

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.5) Gecko/20070713 Firefox/2.0.0.5 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.5) Gecko/20070713 Firefox/2.0.0.5 Using just a <button></button> set of tags inside a form causes the form to submit when clicked. If I put "type='button'" on the tag, it will function like it is supposed to, doing nothing. Consider the following HTML: <form action='edit.aspx' name='Add' method=post></form> <form action='SelectedShow.aspx' name='Select' ID='Select' method=post> <input type=button value='Add Input' onclick='Add.submit();'> <button type=button onclick='Add.submit();'>Add Button With Type</button> <button onclick='Add.submit();'>Add Button Without Type</button> <button>Plain Button</button> </form> The first button is a <input type='Button'>. This creates a button that does nothing except with JavaScript. The JavaScript attempts to submit a different form in this case. The second button is a <button type='Button'>. It functions exactly the same as the above button. The third button is a <button> without a type. You can see that it has JavaScript that submits the form when click. However, since the <button> without a type incorrectly acts like a submit button, the JavaScript has no effect. (Actually, if you click the button and then press back, you find that it did submit the Add form, but it also submitted the Select form, so you get two entries in the history.) The forth button has no type and no JavaScript. When clicked, it incorrectly acts like a submit button. Reproducible: Always Steps to Reproduce: 1. Copy the above HTML into an HTML file 2. Click the third button, watch as it submits the form it is within. Click the back button and you will find that the browser is pointing to Edit.ASPX. Click back one more time and you will be on the original page. 3. Click the forth button, watch as it submits the form it is within. Actual Results: Form is submitted when it shouldn't be Expected Results: <button> tag with no type should not do anything unless JavaScript is attached.
You are mistaken about what a button should do by default. The button element's default type is submit, which submits the form it is in. http://www.w3.org/TR/html4/interact/forms.html#adef-type-BUTTON
Status: UNCONFIRMED → RESOLVED