HTML onsubmit event attribute

Example

Execute a JavaScript when the form is submitted:

<form action="demo_form.asp" onsubmit="checkForm()">

Try it yourself

Browser support

IE Firefox Chrome Safari Opera

All major browsers support the onsubmit attribute.

Definition and usage

The onsubmit attribute triggers when a form is submitted.

The onsubmit attribute is only used in <form>.

Differences between HTML 4.01 and HTML5

None.

Syntax

<form onsubmit="script">

Attribute value

Value Description
script Script that runs when onsubmit occurs.