Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the difference between onclick and onsubmit?

Tags:

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

like image 921
user3636516 Avatar asked May 20 '14 14:05

user3636516


1 Answers

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.

like image 190
Halcyon Avatar answered Oct 23 '22 20:10

Halcyon