Form confirmation on submit

后端 未结 5 1549
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-21 03:58

I want to have a confirmation from the user before they submit a form. This will prevent accidental POSTing of the form, that may be incomplete or incorrect.

Here is my

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-21 04:29

    First of all you should reconsider your approach. Instead of asking whether the user wants to submit a potentially incomplete or invalid form, you should use javascript to prevent this from happening, i.e. perform client-side validation using js. What you are doing is inherently done by clicking submit...

    If however you want to keep your approach, you have to prevent the submit button from actually submitting the data to the specified action, e.g by changing the form action to "#" via javascript and then trigger the submit if ok was clicked with your js-code, e.g. by using a XmlHttpRequest.

提交回复
热议问题