HTMLFormElement.submit() stops working if a submit button removes itself from the form during its click event handler




9 years ago
2 years ago


(Reporter: julien.cheritat, Unassigned)


(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)



(1 attachment)



9 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv: Gecko/20100722 Firefox/3.6.8

When an <input type=submit> element removes itself during its click event, the submit() method stops working on the parent form element.

Here is a small example to demonstrate this issue :

Reproducible: Always

Steps to Reproduce:
1.Create an HTML file with the content given below
2.Open this file in Firefox (same issue in K-meleon)
3.Click on the "remove" button
4.Click on the "JS submit" button
Actual Results:  
Nothing happens

Expected Results:  
The form should be submitted

Html file used to reproduce :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns=""><head><title></title>
	<script>function c(){ document.forms[0].removeChild(document.getElementById("a3")); return false;}</script>
	<form method="get" id="test" action="">
		<input type="button" value="JS submit" onclick="document.forms[0].submit()" name="a1"/>
		<input type="submit" value="Form submit" name="a2" />
		<input type="submit" value="removed" onclick="return c();" name="a3" id="a3"/>

Comment 1

9 years ago
Created attachment 464860 [details]
File used to reproduce the issue
> The form should be submitted


Here's what the HTML5 spec has to say:

  The element's activation behavior, if the element has a form owner, is to
  submit the form owner from the input element; otherwise, it is to do nothing.

Activation behavior is the default action, so happens after user-defined event handlers have fired.  Since the event handler removes the input from the form, the input no longer has a form owner at activation time, so nothing happens.

Which is exactly the behavior I see in Gecko, Webkit, and Presto.
Last Resolved: 9 years ago
Resolution: --- → INVALID

Comment 3

8 years ago
The "JS submit" button has document.forms[0].submit(), clicking on it MUST submit the form.
Resolution: INVALID → ---
Oh, I see.  I thought you meant that clicking the "removed" button was supposed to submit it.

Confirming; presumably the issue is something to do with pending submissions not being cleared out when the third button is removed...
Ever confirmed: true

Comment 5

5 years ago
This bug also affects modern platforms (tested Ubuntu Linux 13.10 and Windows 7, but it's probably platform-independent). Please update when you're able.
Blocks: 847845

Comment 6

4 years ago
Description and solution to the problem:!topic/
Breaks's search page - if you select things in the autocomplete menu it doesn't submit. See

Comment 8

2 years ago
For anyone else looking at this, a workaround appears to be setting the button's type property to "button" -
You need to log in before you can comment on or make changes to this bug.