Bootstrap 3 modal is closed when enter is pressed, but form is not submitted
you can simply change the order from
close-buttonsubmit-button
to
submit-buttonclose-button
or add
type="button"
to your close button so it doesn´t get interpreted as submit button
cheers
I've added a handler to the modal close event to submit the form before closing the modal, like so:
$("#myModal").on("hide.bs.modal", function () { $(this).find('form').submit(); });
I've updated the jsfiddle correspondingly, http://jsfiddle.net/yAzrs/2/
You could also listen for the enter key within the form itself, something like this:
$('form').on("keypress", function (e) { if (e.which == 13) $(this).submit();});
have you tried using
$(document).keypress(function(e) { if(e.which == 13) { alert('You pressed enter!'); }});
jQuery doesn't know you've pressed enter just simply by you pressing enter. Include the jQuery above but with your own code inside the if statement and hopefully it should work