Focus on a text field

by Renan Ribeiro Brando

HTML

<!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus -->

<input type="text" id="myTextField" value="Text field.">
<p></p>
<button type="button" onclick="focusMethod()">Click me to focus on the text field!</button>

JavaScript

focusMethod = function getFocus() {           
  document.getElementById("myTextField").focus();
}