I have a simple form with fields that I am trying to validate using JavaScript. In the form I have an input type of submit.
For validation, should I call the validation function for onclick event on the input or onsubmit of the form? Is there any implication of choosing one over the other one?
onsubmitis triggered whenever the form is about to be submitted.onclickis triggered when the specific button is clicked.Forms can be submitted by hitting the enter key in any input field. This would not trigger the
onclickof the submit button, but it would trigger the form submit event. As such, useonsubmit.