set focus javascript
snippet in javascript

set focus javascript

user5915

document.getElementById("ThingToSetFocusOn").focus();

focus js

user4687

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

focus js

user2972

// GIVE FOCUS TO A TEXT FIELD IMMEDIATELY AFTER WINDOW LOADS

 window.onload = function() {
  document.getElementById("myText").focus();
}; 

focus js

user8546

// ElementObject grabs focus

 HTMLElementObject.focus()

focus js

user7088

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