This StackOverflow question asks to find the button, that triggered a
submit form event from within an
submit event handler. Use cases for this are a dime a dozen, when you think of serializing the form data for AJAX requests and more than one submit buttons in the
My answer was to use
document.activeElement for this, but it has some shortcomings, like any of the other answers, too.
Therefore adding a property to the dispatched
submit event that links to the initiator of the submission would help here. The property references the DOM element, that was activated for the form submission. Something along the following lines:
submitteron an event of type
When a form is submitted, the
submitevent created according to HTML5.1, Form submission algorithm contains a property
- If the form was submitted via click on a submit button,
event.submitterreferences the button.
- If the form was submitted implicitly, e.g., by hitting
enterin a text input field,
event.submitterreferences the form’s default button as defined in Implicit submission
- If the form was submitted with its
event.submitter = null.