Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
SweetAlert isConfirm does not work properly

I want to show a Sweet Alert 2 confirm message to user after submitting the form like this:

<form id="myForm" data-flag="0" action="" method="POST">
   @csrf
   <input type="checkbox" id="btn-submit" name="wallet_checked" onchange="this.form.submit();">
</form>

As you can see I have used onchange="this.form.submit();" to submit the form without using submit button and it works fine.

Then I tried adding this as script for showing SweetAlert message to user:

 $(document).on('click', '#btn-submit', function(e) {
    e.preventDefault();
    let form = $(this).parents('form');
    swal(
        {
        title: "Attention!",
        text: "Are you sure you want to make this",
        type: "warning",
        allowEscapeKey: false,
        allowOutsideClick: false,
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes",
        cancelButtonText: "No",
        showLoaderOnConfirm: true,
        closeOnConfirm: false
    },

    function (isConfirm) {
        if (isConfirm) {
            console.log("YES");
        }
        return false;
    });
});

So the function shows Sweet Alert message on screen after clicking on the checkbox, but when I press on Yes button, it does not run console.log("YES");.

And this means that if (isConfirm) { at function (isConfirm) { is not working properly.

So how to solve this issue? What is wrong with isConfirm?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Change this to :

 $(document).on('click', '#btn-submit', function(e) {
    e.preventDefault();
    let form = $(this).parents('form');
    swal(
        {
        title: "Attention!",
        text: "Are you sure you want to make this",
        type: "warning",
        allowEscapeKey: false,
        allowOutsideClick: false,
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes",
        cancelButtonText: "No",
        showLoaderOnConfirm: true,
        closeOnConfirm: false
    })
    .then((isConfirm) => {
        if (isConfirm) {
            console.log("YES");
        }
        return false;
    });
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!