How can I show SweetAlert in this JavaScript code?
function removeReg(del_reg) {
if (confirm("Are you sure you want to delete? \n the reg name : " + del_reg)) {
// Code goes here
}
}
I just want to call SweetAlert in the if condition, i.e. in SweetAlert, I need to show the message "Are you sure you want to delete?".
Call swal() with your custom options in the removeReg(del_reg) function and use the Promise returned by swal() to determine what is the user's choice:
YES, the returned value will be trueNO or pressed the Esc key, the returned value will be nullvar button = document.getElementById('remBtn')
function removeReg(del_reg) {
swal({
text: "Are you sure you want to delete? \n the reg name : " + del_reg,
icon: "error",
buttons: ['NO', 'YES'],
dangerMode: true
})
.then(function(value) {
console.log('returned value:', value);
});
}
button.addEventListener('click', function() {
console.log('clicked on button')
removeReg('SomeCustomRegName');
});
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<button id="remBtn">Remove Registered Name</button>
More on the advanced examples of SweetAlert
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With