You can use the autofocus attribute to automatically give focus to an input element.
<input id="sample" autofocus>
If your browser does not support the autofocus attribute, you can use JavaScript to give focus to an input element:
if (!("autofocus" in document.createElement("input"))) { document.getElementById("sample").focus(); }
In this example, the second form element includes the autofocus attribute.