0

I want to show an alert box before form submission.

If a user presses yes, then the form will submit, otherwise it wont. Is there a solution using jQuery?

djlumley
  • 2,879
  • 2
  • 23
  • 30
Nur
  • 23
  • 1
  • 2
  • 10

3 Answers3

10

you can use the javascript confirm(message) : boolean function by intercepting the submit event of html form.

$("#html_form").submit(function(e){
    if (!confirm("should i really submit"))
    {
        e.preventDefault();
        return;
    } 
});
Roman
  • 10,126
  • 17
  • 62
  • 99
3
$('#yourform').submit(function(e) {
    if(!confirm('really submit the form?')) {
        e.preventDefault();
        return;
    }
    // submit the form via ajax, e.g. via the forms plugin
    // http://jquery.malsup.com/form/
});
ThiefMaster
  • 298,938
  • 77
  • 579
  • 623
0

Read this post...

Confirmation Posts Yes/No Submit

May be this will help you out.

Community
  • 1
  • 1
JN_newbie
  • 4,022
  • 9
  • 52
  • 85