How can I auto focus an input on modal show? Currently I do this but it isn't working:
jQuery(document).ready(function($) {
$('#myModal').on('show.bs.modal', function() {
$('input[name="myInput"]').focus();
});
});
How can I auto focus an input on modal show? Currently I do this but it isn't working:
jQuery(document).ready(function($) {
$('#myModal').on('show.bs.modal', function() {
$('input[name="myInput"]').focus();
});
});
Your code is basically correct. But the event show.bs.modal
is triggerede before the modal has been shown. You need to use shown.bs.modal
event instead.
jQuery(function($) {
$('#myModal').on('shown.bs.modal', function() {
$('input[name="myInput"]').focus();
});
});
In Your code, Use autofocus
<input name="myInput" value="MyVal" type="text" autofocus/>