+ 2

Hello guys,whats the difference between "onclick",and" onsubmit"

Javascript

31st May 2020, 1:07 PM
Irine Nabwire
Irine Nabwire - avatar
3 ответов
+ 4
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 onkeydownfor detecting key presses on the keyboard.
31st May 2020, 1:14 PM
Abdulsalam Al-Ashwal
Abdulsalam Al-Ashwal - avatar
+ 1
onclick gets triggered when you click on something onsubmit - when you submit a form https://www.sololearn.com/learn/JavaScript/2758/
31st May 2020, 1:14 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Hi, 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.
1st Jun 2020, 9:16 AM
AjayGohil