Name
Form.onsubmit: event handler invoked when a form is submitted â DOM Level 0
Synopsis
Function onsubmit
Description
The onsubmit
property of a
Form object specifies an event-handler function that is invoked when
the user submits a form by clicking on its Submit button. Note that this event handler
is not invoked when the Form.submit(
)
method is called.
If the onsubmit
handler
returns false
, the elements of
the form are not submitted. If the handler returns any other value
or returns nothing, the form is submitted normally. Because the
onsubmit
handler can cancel form
submission, it is ideal for performing form data validation.
See Element.addEventListener(
)
for another way to register event handlers.
See Also
Element.addEventListener(
)
, Form.onreset
,
Form.submit( )
; Chapter 17
Get JavaScript: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.