I have a dummy Bootstrap modal with a very simple JS alert meant to be triggered when the submit button is clicked. The code is live here and this is what it looks like:
<div class="modal fade" id="contact" role="dialog" >
<form class="form-horizontal" role="form" name="contact-form">
<div class="modal-body"><p>This is body</p></div>
<button type="submit" id="submit" class="btn btn-primary btn-lg" onclick="alert('something');">Send</button>
At first I thought that it happens because the button has property
type set to
submit, so I'd recommend to remove this property completely, and the trailing question mark would probably not appear anymore. But it does.
What really needs to be done is event default action has to be prevented. To do that, return
false right there in the
onclick event callback function:
<button onclick="alert('something'); return false;">...</button>
This way you, well, return false, and this is perceived as if you want to prevent further execution of the click event, effectively submit operation.