HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptCritical

How can I open a Bootstrap modal window using jQuery?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howjqueryusingcanbootstrapopenmodalwindow

Problem

I'm using the Twitter Bootstrap modal window functionality. When someone clicks Submit on my form, I want to show the modal window upon clicking the "submit button" in the form.

Bootstrap Wizard Form




×
Modal header



One fine body…


Close
Save changes




jQuery:
$('#myform').on('submit', function(ev) {
$('#my-modal').modal({
show: 'false'
});

var data = $(this).serializeObject();
json_data = JSON.stringify(data);
$("#results").text(json_data);
$(".modal-body").text(json_data);

// $("#results").text(data);

ev.preventDefault();
});

Solution

Bootstrap has a few functions that can be called manually on modals:

$('#myModal').modal('toggle');
$('#myModal').modal('show');
$('#myModal').modal('hide');


You can see more here: Bootstrap modal component

Specifically the methods section.

So you would need to change:

$('#my-modal').modal({
    show: 'false'
});


to:

$('#myModal').modal('show');


If you're looking to make a custom popup of your own, here's a suggested video from another community member:

How to create a custom popup using jQuery and CSS

Code Snippets

$('#myModal').modal('toggle');
$('#myModal').modal('show');
$('#myModal').modal('hide');
$('#my-modal').modal({
    show: 'false'
});
$('#myModal').modal('show');

Context

Stack Overflow Q#13183630, score: 1813

Revisions (0)

No revisions yet.