Focus onload

In: JavaScript

August 02nd, 2010.

It is useful to focus on input field after page is loaded when user is presented with login form. Once page is loaded we shall set focus on input field so user would not need to use mouse in order to focus on it.

1
2
3
4
5
6
7
8
<input type="text" id="my-onload-focus-input" />
 
<script>
function focus_onload() {
	document.getElementById('my-onload-focus-input').focus();
}
window.onload = focus_onload();
</script>

Written by

Dejan is pragmatic software developer with Master's Degree in Computer Science. He is currently based in Belgrade (Serbia).