You are here: irt.org | FAQ | JavaScript | Form | 2 | Q246 [ previous next ]
The following does not always work:
<BODY onLoad="document.forms[0].elements[0].focus()"> <FORM> <INPUT TYPE="TEXT" VALUE="1234"> </FORM>
Try either the following:
<HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"><!-- function setFocus() { document.forms[0].elements[0].focus(); } //--></SCRIPT> </HEAD> <BODY onLoad="setTimeout('setFocus()',1)"> <FORM> <INPUT TYPE="TEXT" VALUE="1234"> </FORM> </BODY> </HTML>
Or:
<FORM> <INPUT TYPE="TEXT" VALUE="1234"> </FORM> <SCRIPT LANGUAGE="JavaScript"><!-- document.forms[0].elements[0].focus(); //--></SCRIPT>