Nur
Nur

Reputation: 25

Confirmation of Form Submission using jQuery

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?

Upvotes: 0

Views: 11428

Answers (3)

JN_newbie
JN_newbie

Reputation: 6102

Read this post...

Confirmation Posts Yes/No Submit

May be this will help you out.

Upvotes: 0

ThiefMaster
ThiefMaster

Reputation: 318798

$('#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/
});

Upvotes: 3

Roman
Roman

Reputation: 10403

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;
    } 
});

Upvotes: 10

Related Questions