van cabrera van cabrera - 1 month ago 7
Javascript Question

How to call a bootstrap modal after 'sweetAlert' alert 'ok' clicked?

I want to call the bootstrap modal after I click the "OK" button on a

sweetAlert
Alert.

So, after the user click the
OK
button on the
sweetAlert
alert. It will call the bootstrap modal automatically. I tried that code below in the javascript but didn't worked.

BOOTSTRAP MODAL

<div class="modal fade" id="change_password" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<div class="modal-body change_password">
</div>
</div>
</div>
</div>


JS CODE

<script language='javascript'>
swal({
title: 'Sample Title',
text: 'Hi',
type: 'success',
allowOutsideClick: true,
html: true
},
function () {
$('#change_password').modal('show');
});
</script>

Answer

your code is working fine

swal({
    title: 'Sample Title',
    text: 'Hi',
    type: 'success',
    allowOutsideClick: true,
    html: true
},
function () {
    $('#change_password').modal('show');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="modal fade" id="change_password" role="dialog">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>
            <div class="modal-body change_password">
                Modal body
            </div>
        </div>
    </div>
</div>

Comments