I'm using 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.
<form id="myform" class="form-wizard">
<h2 class="form-wizard-heading">BootStap Wizard Form</h2>
<input type="text" value=""/>
<input type="submit"/>
</form>
<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
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();
});
Just call the modal method(without passing any parameters) using
jQuery
selector.Here is example:
If you use links's onclick function to call a modal by jQuery, the "href" can't be null.
For example:
The Modal can't show. The right code is :
I tried several methods which failed, but the below worked for me like a charm:
You can launch the modal with the code below this.
Here is how to load bootstrap alert as soon as the document is ready. It is very easy just add
I made a demo on W3Schools.
Most often, when
$('#myModal').modal('show');
doesn't work, it's caused by having included jQuery twice. Including jQuery 2 times makes modals not to work.Remove one of the links to make it work again.
Furthermore, some plugins cause errors too, in this case add