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,955
  • 2
  • 24
  • 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,309
  • 17
  • 66
  • 101
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
  • 310,957
  • 84
  • 592
  • 636
0

Read this post...

Confirmation Posts Yes/No Submit

May be this will help you out.

Community
  • 1
  • 1
JN_newbie
  • 5,492
  • 14
  • 59
  • 97