HTMLFormElement: Submit Event - Web APIs | MDN
Có thể bạn quan tâm
- Skip to main content
- Skip to search
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
- Learn more
- See full compatibility
- Report feedback
The submit event fires when a <form> is submitted.
Note that the submit event fires on the <form> element itself, and not on any <button> or <input type="submit"> inside it. However, the SubmitEvent which is sent to indicate the form's submit action has been triggered includes a submitter property, which is the button that was invoked to trigger the submit request.
The submit event fires when:
- the user clicks a submit button,
- the user presses Enter while editing a field (e.g., <input type="text">) in a form,
- a script calls the form.requestSubmit() method
However, the event is not sent to the form when a script calls the form.submit() method directly.
Note: Trying to submit a form that does not pass validation triggers an invalid event. In this case, the validation prevents form submission, and thus there is no submit event.
In this article
- Syntax
- Event type
- Event properties
- Examples
- Specifications
- Browser compatibility
- See also
Syntax
Use the event name in methods like addEventListener(), or set an event handler property.
jsaddEventListener("submit", (event) => { }) onsubmit = (event) => { }Event type
A SubmitEvent. Inherits from Event.
Event SubmitEventEvent properties
In addition to the properties listed below, this interface inherits the properties of its parent interface, Event.
submitter Read onlyAn HTMLElement object which identifies the button or other element which was invoked to trigger the form being submitted.
Examples
This example uses EventTarget.addEventListener() to listen for form submit, and logs the current Event.timeStamp whenever that occurs, then prevents the default action of submitting the form.
HTML
html<form id="form"> <label>Test field: <input type="text" /></label> <br /><br /> <button type="submit">Submit form</button> </form> <p id="log"></p>JavaScript
jsconst form = document.getElementById("form"); const log = document.getElementById("log"); function logSubmit(event) { log.textContent = `Form Submitted! Timestamp: ${event.timeStamp}`; event.preventDefault(); } form.addEventListener("submit", logSubmit);Result
Specifications
| Specification |
|---|
| HTML# event-submit |
| HTML# handler-onsubmit |
Browser compatibility
See also
- HTML <form> element
- Related event: invalid
Help improve MDN
Was this page helpful to you? Yes No Learn how to contributeThis page was last modified on Oct 1, 2025 by MDN contributors.
View this page on GitHub • Report a problem with this content Filter sidebar- The HTML DOM API
- HTMLFormElement
- Instance properties
- acceptCharset
- action
- autocomplete
- elements
- encoding
- enctype
- length
- method
- name
- noValidate
- rel
- relList
- target
- Instance methods
- checkValidity()
- reportValidity()
- requestSubmit()
- reset()
- submit()
- Events
- formdata
- reset
- submit
- Inheritance
- HTMLElement
- Element
- Node
- EventTarget
- Related pages for HTML DOM
- BeforeUnloadEvent
- DOMStringMap
- ErrorEvent
- HTMLAnchorElement
- HTMLAreaElement
- HTMLAudioElement
- HTMLBRElement
- HTMLBaseElement
- HTMLBodyElement
- HTMLButtonElement
- HTMLCanvasElement
- HTMLDListElement
- HTMLDataElement
- HTMLDataListElement
- HTMLDialogElement
- HTMLDivElement
- HTMLDocument
- HTMLElement
- HTMLEmbedElement
- HTMLFieldSetElement
- HTMLFormControlsCollection
- HTMLFrameSetElement Deprecated
- HTMLHRElement
- HTMLHeadElement
- HTMLHeadingElement
- HTMLHtmlElement
- HTMLIFrameElement
- HTMLImageElement
- HTMLInputElement
- HTMLLIElement
- HTMLLabelElement
- HTMLLegendElement
- HTMLLinkElement
- HTMLMapElement
- HTMLMediaElement
- HTMLMenuElement
- HTMLMetaElement
- HTMLMeterElement
- HTMLModElement
- HTMLOListElement
- HTMLObjectElement
- HTMLOptGroupElement
- HTMLOptionElement
- HTMLOptionsCollection
- HTMLOutputElement
- HTMLParagraphElement
- HTMLPictureElement
- HTMLPreElement
- HTMLProgressElement
- HTMLQuoteElement
- HTMLScriptElement
- HTMLSelectElement
- HTMLSourceElement
- HTMLSpanElement
- HTMLStyleElement
- HTMLTableCaptionElement
- HTMLTableCellElement
- HTMLTableColElement
- HTMLTableElement
- HTMLTableRowElement
- HTMLTableSectionElement
- HTMLTemplateElement
- HTMLTextAreaElement
- HTMLTimeElement
- HTMLTitleElement
- HTMLTrackElement
- HTMLUListElement
- HTMLUnknownElement
- HTMLVideoElement
- HashChangeEvent
- History
- ImageData
- Location
- MessageChannel
- MessageEvent
- MessagePort
- Navigator
- PageRevealEvent
- PageSwapEvent
- PageTransitionEvent
- Plugin Deprecated
- PluginArray Deprecated
- PromiseRejectionEvent
- RadioNodeList
- TimeRanges
- UserActivation
- ValidityState
- Window
- WorkletGlobalScope
- Guides
- Using microtasks in JavaScript with queueMicrotask()
- In depth: Microtasks and the JavaScript runtime environment
Từ khóa » Html Form Block Submit
-
How To Prevent Form From Being Submitted? - Stack Overflow
-
Prevent HTML
-
Prevent Form Submission JavaScript | Delft Stack
-
Html Form Prevent Submit Code Example - Code Grepper
-
Form Onsubmit Prevent Default Code Example - Code Grepper
-
2 Methods To Prevent Form From Submission - HTML & Javascript
-
How To Prevent Buttons From Causing A Form To Submit With HTML
-
How To Disable The Submit Button While A Form Is Submitting In Webflow
-
HTML DOM Input Submit Disabled Property - W3Schools
-
PreventDefault() Event Method - W3Schools
-
How To Stop A Form Submit Action Using JQuery ? - GeeksforGeeks
-
JavaScript Stop Form Submit - Daily Dev Tips
-
Javascript: Prevent Double Form Submission - The Art Of Web
-
Html Form Prevent Submit When Hit Enter On Specific Input