I'm trying to set the sweetalert pop-up messages while clicking the edit button .
here is the sample code:
<td><a href="/control/edituser/{{Values.id}}" onclick='a' class="btn btn-info">Edit</a></td>
script:
<script>
$('a').click(function(e){
e.preventDefault();
var link = $(this).attr('href');
swal({
title: "Are you sure?",
text: "By clicking 'OK' you will be redirected to the link.",
type: "warning",
showCancelButton: true
},
function(){
window.location.href = link;
});
});
</script>
There're a few gotchas about your code mate. First off, is why are you using
onclick='a'when you have not defined a function and instead relied on jQuery to detect the click event? Either use jQuery or trigger a function call usingonClick.Second thing is that you need to check for confirmation in order to trigger your desired action.
Further reading:
How to use confirm using sweet alert?
Using an HTML button to call a JavaScript function