I am trying to set the default button in a bootstrap modal. Here is the code: http://plnkr.co/edit/1aLlDdL8WfkUrBVt4q31?p=preview
In the modal window, I want the Submit button to be the default.
I tried to follow code but did not work.
$("#userNameModal").keyup(function(event){
if(event.keyCode == 13){
$("#submitUserNameBtn").click();
}
});
Any help is appreciated.
To trigger the modal window, you need to use a button or a link. Then include the two data-* attributes: data-toggle="modal" opens the modal window. data-target="#myModal" points to the id of the modal.
Answer: Use the Bootstrap . modal('show') method modal('show') method for launching the modal window automatically when page load without clicking anything. A common example of this technique is loading the modal when user landed on the home page and requesting them to subscribe the website newsletter.
$('#buttonId'). off('click'). click(function(clickEvent){ //enter code here }); you actually can prevent the closing of your modal.
The backdrop option specifies whether the modal should have a dark overlay (the background color of the current page) or not.
Wrap the code with <form>
and set correct button types: type="submit"
for Submit button and type="button"
for other ones.
The modified plunker: http://plnkr.co/edit/XD2UzlBnPbBafWmWfTg0?p=preview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With