Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close Bootstrap modal on form submit

I have a Bootstrap modal dialog which contains a form. The modal dialog contains a submit and a cancel button. Now on submit button click the form is submitted successfully but the modal dialog isn't getting closed. Here is my HTML:

<div class="modal fade" id="StudentModal" tabindex="-1" role="dialog" aria-labelledby="StudentModalLabel" aria-hidden="true" data-backdrop="static">    <div class="modal-dialog">       <div class="modal-content">          <form action="~/GetStudent" class="form-horizontal" role="form" method="post" id="frmStudent">             <div class="modal-footer">                <div class="pull-right">                   <button type="submit" class="btn btn-success"><i class="glyphicon glyphicon-ok"></i> Save</button>                   <button type="button" class="btn btn-danger" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> Close</button>                </div>             </div>          </form>       </div>    </div> 

Anybody knows how to do this?

like image 838
Lara Avatar asked Nov 02 '15 12:11

Lara


People also ask

How do you close modal after submit in Bootstrap?

There are few ways to close modal in Bootstrap: click on a backdrop, close icon, or close button. You can also use JavaScript hide method. Click the button to launch the modal. Then click on the backdrop, close icon or close button to close the modal.

How do I submit a Bootstrap modal form?

You CAN include a modal within a form. In the Bootstrap documentation it recommends the modal to be a "top level" element, but it still works within a form. You create a form, and then the modal "save" button will be a button of type="submit" to submit the form from within the modal.

How do I stop a Bootstrap modal from closing?

If you want to prevent boostrap modal from closing by those actions, you need to change the value of backdrop and keyboard configuration. The default value of backdrop and keyboard is set to true . You can change the configuration in HTML or Javascript directly.

How do you make a modal close?

To close the modal, simply call the handleClose() function inside the onLoginFormSubmit() function body.


1 Answers

Use that Code

 $('#button').submit(function(e) {     e.preventDefault();     // Coding     $('#IDModal').modal('toggle'); //or  $('#IDModal').modal('hide');     return false; }); 
like image 101
Muhammad Fahad Avatar answered Oct 05 '22 14:10

Muhammad Fahad