I have a hyperlink like this:
<a href="{{ route('courseRegistration', $item->cor_id) }}" class="btn btn-info" id="custombtn">
Register
</a>
Then I added this to show a Sweetalert message with Yes and No buttons:
$(document).on('click', '#custombtn', function(e) {
e.preventDefault();
let form = $(this).parents('form');
swal(
{
title: "Alert!",
text: "You have an active Wallet, do you wish to pay the price with the active Wallet?",
type: "warning",
allowEscapeKey: false,
allowOutsideClick: false,
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
showLoaderOnConfirm: true,
closeOnConfirm: false
}).then((isConfirm) => {
if (isConfirm.value === true) {
// go to the href route
}
return false;
});
});
As you can see I want to say: if user clicked on the Yes button, goto href route and if not, stays on the page (return false).
So the question is, how can I redirect user to href="{{ route('courseRegistration', $item->cor_id) }}", if he clicks on Yes button?
you can use window.location.href = "YOURLINKHERE" to redirect to another page after checking if isConfirm.value is set (you dont have to check for true, since the cancel Button doesn't return isConfirm.value)