To set focus on an element in an HTML form using JavaScript, we call the input’s focus
method.
For instance, we write
<input type="text" id="myText" />
to add an input.
Then we write
document.getElementById("myText").focus();
to select the input with getElementById
.
Then we call focus
to set focus on it.