Should I use the input's onclick or the form's onsubmit event to validate form fields using JavaScript?

前端 未结 2 1055
旧时难觅i
旧时难觅i 2021-01-18 09:53

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 val

2条回答
  •  余生分开走
    2021-01-18 10:14

    Both onclick and onsubmit do the same thing. No matter you press enter on a text input element or press submit button, both are triggered. If you use both onclick and onsubmit events, they are both executed respectively. And if You have more than one submit buttons in the form, the first submit button's onclick method is executed. Tested on Internet Explorer, Firefox, Chrome and Opera.

提交回复
热议问题