Javascript DOM HTML Input Text get focus on document load

Introduction

Give focus to a text field, immediately after the document window has been loaded:

In this example, the text field gets focus immediately after the document window has been loaded.

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="text" id="myText" value="A text field">

<script>
window.onload = function() {/*from   w  w w. j a  v a  2  s.  c om*/
  document.getElementById("myText").focus();
};
</script>

</body>
</html>



PreviousNext

Related