JavaScript Form Submit - Confirm or Cancel Submission Dialog Box

匿名 (未验证) 提交于 2019-12-03 02:05:01

问题:

For a simple form with an alert that asks if fields were filled out correctly, I need a function that does this:

  • Shows an alert box when button is clicked with two options:

    • If "OK" is clicked, the form is submitted
    • If cancel is clicked, the alert box closes and the form can be adjusted and resubmitted

I think a JavaScript confirm would work but I can't seem to figure out how.

The code I have now is:

回答1:

A simple inline JavaScript confirm would suffice:

No need for an external function unless you are doing validation, which you can do something like this:



回答2:

function show_alert() {   if(confirm("Do you really want to do this?"))     document.forms[0].submit();   else     return false; } 


回答3:

You could use the JS confirm function.

http://jsfiddle.net/jasongennaro/DBHEz/



回答4:



回答5:

OK, just change your code to something like this:

Also this is the code in run, just I make it easier to see how it works, just run the code below to see the result:

function submitForm() {   return confirm('Do you really want to submit the form?'); }


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!