JavaScript Confirmation form Message

Jumper

I have a confirmation message in my form with JS script but the value of "verif" always false or I do not know where is the problem; If I boot "verif" with false, it's still false

    function valider() {
    var verif = false;
    swal({
        title: "Are you sure?",
        text: "You will not be able to recover       this  file!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes, delete it!",
        cancelButtonText: "No, cancel plx!",
        closeOnConfirm: false,
        closeOnCancel: false
    }, function(isConfirm) {
        if (isConfirm) {
            swal("Deleted!", "Your  file has been deleted.", "success");
            verif = true;
            alert("afficher");
        } else {
            swal("Cancelled", "Your  file is safe :)", "error");
            verif = false;
            swal("afficher");
        }
    });

    if (verif) {
        $("#formulaire").submit();
    }

    return false;
}



$("#envoyer").click(function() {
    valider();
    return false;
});

and this is the HTML Code

<form action="archi.php" method="post" class="form-horizontal"     id="formulaire">

<div class="form-actions">
<button type="submit" id="envoyer" class="btn blue envoyer">  <i    class="icon-save"></i> Archiver</button>
<button type="button" class="btn">Cancel</button>
</div>
</form>
zmii

Why do you add another test for submitting? Add submit to the callback function and delete additional if:

function valider() {
    var verif = false;
    swal({
        title: "Are you sure?",
        text: "You will not be able to recover       this  file!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes, delete it!",
        cancelButtonText: "No, cancel plx!",
        closeOnConfirm: false,
        closeOnCancel: false
    }, function(isConfirm) {
        if (isConfirm) {
            $("#formulaire").submit();  
            swal("Deleted!", "Your  file has been deleted.", "success");
        } else {
            swal("Cancelled", "Your  file is safe :)", "error");
            swal("afficher");
        }
    });

    return false;
}



$("#envoyer").click(function() {
    valider();
    return false;
});

P.S. Try adding a console.log() before the return from verif() function to check if the }, function(isConfirm) { is async (this would clarify all misunderstanding).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Confirmation message not displaying on javascript contact form

Confirmation message for form submission after validations in JavaScript

Confirmation message - Javascript rails application

Contact form doesn't show confirmation message in HTML

Javascript to trigger an alert message on a form

Javascript message is not rendering in HTML form

Password confirmation message

ZK Message Box Confirmation

Hyperlink alias in confirmation message

Message (alert) asking for confirmation

Confirmation message is not working

Redirect to same page after successful submission of a form and clicking OK on a confirmation message

On form, how to get multiple checked checkbox value and add to mysql with php without reload and show confirmation message in div?

angularjs password confirmation not display confirmation message

Require Confirmation on Form Submission

Confirmation delete message kendo grid

Message box confirmation on button press

How to avoid Firefox confirmation message?

confirmation yes or no message in asp net

Remove user button with confirmation message

Override Wagtail delete confirmation message

Javascript comfirmation message to stop form submission

Javascript form validation: custom error message

Function to form message from text [JavaScript]

javascript form validaton, Validation message Disappear Quickly

Error message not working in simple javascript form validation

multiple form validation error message in single alert message javascript

(PHP) Javascript confirmation alert

Passing form data to a confirmation view