Skip to content

Instantly share code, notes, and snippets.

@mikechau
Last active April 6, 2023 10:53
Show Gist options
  • Save mikechau/6159049 to your computer and use it in GitHub Desktop.
Save mikechau/6159049 to your computer and use it in GitHub Desktop.
Bootstrap Modal, ajax submit, and close on submit
$(function(){
$('#myFormSubmit').click(function(e){
e.preventDefault();
alert($('#myField').val());
$('#myModal').modal('hide')
/*
$.post('http://path/to/post',
$('#myForm').serialize(),
function(data, status, xhr){
// do something here with response;
});
*/
});
});
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>
<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">
<form id="myForm" method="post">
<input value="hello" id="myField" type="hidden">
</form>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary" id="myFormSubmit" type="submit">Submit</button>
</div>
</div>
@Nallathambi95
Copy link

bb jhb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment