Q:

jquery show a confirm alert before submitting

jQuery('document').ready(function(){
jQuery('#survey').on('click', function(){
    var postData = jQuery('#surveyForm').serialize();

    jQuery.post('survey.php', postData, function(data){
        alert(data);
     if($.trim(data) == "Your Score sent Successfully!") {
            location.reload();  
        }

    });     
});

});
this is my jquery code, can any one please help me how to add a confirm alert "are u sure you want to submit" in the above code.
Thanks in advance.

A:

You can use Javascript confirm box as shown :-
jQuery('document').ready(function(){
   jQuery('#survey').on('click', function(){
     if(confirm("Do You want to save?")){
       var postData = jQuery('#surveyForm').serialize();

       jQuery.post('survey.php', postData, function(data){
         alert(data);
         if($.trim(data) == "Your Score sent Successfully!") {
            location.reload();  
         }
       });   
     }  
   });
});

DEMO

