Window Load Event Demo

When this page finishes loading, the demo displays an alert and then focuses and selects the textbox containing plus2net.

Refresh and try again
Return to Tutorial on Window Load

Complete JavaScript Source

function myCode() {
  alert('Alert inside myCode function');
  const textValue = document.getElementById('t2');
  textValue.focus();
  textValue.select();
}

window.addEventListener('load', myCode);

Complete HTML Source

<form name="form1" method="post" action="">
  <label for="t2">Demo textbox</label>
  <input type="text" name="t1" value="plus2net" id="t2">
</form>