Sweet Alert With Confirmation Code In jQuery

Hello guys, Hope you all are doing well. In this article, I will explain how to ask for a confirmation code in Sweetalert.

Prerequisite

You need to attach sweetalert.min.js to your web page.

Add The Below Code

var ConfirmIput = Math.floor(1000 + Math.random() * 9000);

swal({
  title: "<h2 style='color: #575757 !important;'>Are you sure?</h2>",
  text: 'Are you sure you want to update? <br><br> Type ' + ConfirmIput + ' to confirm',
  type: "input",
  showCancelButton: true,
  closeOnConfirm: false,
  animation: "slide-from-top",
  inputPlaceholder: 'Confirmation code',
  html: true,
}, function (inputValue) {
  if (inputValue === "") {
    swal.showInputError("Please enter confirmation code!");
    return false
  }
  if (inputValue == ConfirmIput) {
    swal.close();
    $(".sweet-alert").toggleClass("hideC");		
    //Add your code here that should be executed after confirmation.
  }
  else {
    swal.showInputError("Incorrect confirmation code!");
    return false
  }
});

Output

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories