JavaScript onsubmit Event

The onsubmit event in JavaScript is used with FORM element and is triggered when the form is submitted.

JavaScript onsubmit Event Example

Here is an example demonstrates onsubmit event in JavaScript:

   <title>JavaScript onsubmit Event</title>

<h3>JavaScript onsubmit Event Example</h3>
<form onsubmit="alert('Form Submitted Successfully!')">
   Name:<input type="text" name="name"><br/>
   Branch:<input type="text" name="branch"><br/>
   College:<input type="text" name="clg"><br/>
   Address:<input type="text" name="adr"><br/>
   Email Id:<input type="text" name="eid"><br/>
   <input type="submit" value="SUBMIT">


Here are some sample outputs of the above JavaScript onsubmit event example. This is the initial output:

javascript onsubmit event

Now fill all the field as shown in the following snapshot:

javascript onsubmit event example

After filling all the field, click on SUBMIT button, you will watch an alert box will come out with a message Form Submitted Successfully!. Here is the snapshot of this output:

onsubmit event

Here is the live demo output produced by the above JavaScript onsubmit event example program.

Email Id:

JavaScript Online Test

« Previous Tutorial Next Tutorial »

Liked this article? Share it!

Like/follow us on social media for updates!