By the class that is in the input form-control
it seems to me that you use Bootstrap. In this part in the documentation they indicate that you use the event .on('shown.bs.modal', function () { }
to interact with the modal, so in your case would look like this. See the official documentation https://getbootstrap.com/docs/4.0/components/modal/
$('#myModal').on('shown.bs.modal', function () {
$('#myInput').focus();
})
See the model working.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<style>
</style>
</head>
<body>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
Abrir modal com input focado
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<input type="text" value="sem foco" id="">
<input type="text" value="input com autofocus" id="myInput">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<script>
$('#myModal').on('shown.bs.modal', function () {
$('#myInput').focus();
})
</script>
</body>
</html>
how are you opening this modal? will depend on it!
– novic
By clicking a button it opens with input. I need this input to automatically receive autofocus.
– user120772
Put every example in your question we have no way of knowing what you did there!
– novic