Whats the difference between onclick and onsubmit?

javascript, onclick, onsubmit

Solution

They're two completely separate events.

`onclick` events fire when the user uses the mouse to click on something.

`onsubmit` events fire when a form is submitted. The origin of this event can sometimes be traced back to an `onclick` (like clicking the "submit" button) but it can also come from a keyboard event (like pressing enter).

This implies that using `onclick` on a submit button on a form might miss some cases that an `onsubmit` on the form would catch.

There are many other kinds of events such as: `onload` for loading resources such as scripts or images and `onkeydown` for detecting key presses on the keyboard.

Problem

It's not like I haven't googled it... But still I couldn't understand when `onsubmit` is used and when `onclick` is used?

Original source

Related problems