[removed] validate form before submit?

前端 未结 2 818
[愿得一人]
[愿得一人] 2020-12-18 00:15

I would really appreciate anyone\'s help with this as I just can\'t seem to get it working. I am using a javascript code to check my form before it is submitted. I check for

2条回答
  •  误落风尘
    2020-12-18 01:10

    You should use event.preventDefault(); in your if statement when you check for errors.

    I you are clicking a submit button, first check all the fields, if something fails in your validation, raise event.preventDefault(). With this, this will prevent the form to submit.

    If there are no errors, the preventDefault will not be raised and the form will be submitted.

    Extra information: jQuery API

提交回复
热议问题