Whats the difference between onclick and onsubmit? Whats the difference between onclick and onsubmit? javascript javascript

Whats the difference between onclick and onsubmit?


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.


OnSubmit is used on a form, and indicates that the information is to be submitted to the server at this point unless you return false.

OnClick is used on anything, and indicates that it was clicked, offering no other context to the intention of the event at all.


Onclick is the event where a control/object/pretty much anything, is clicked on. Onsubmit is the event where a form is submitted.

For example, lets say you have a registration form.

You can have the OnClick event of the "Submit" button to bring up an alert that says "Are you sure these details are correct?", and clicking "Ok" there can trigger the OnSubmit event, which would submit the form data to wherever you want it to go.