|
Q246 The onLoad event handler does not always set the focus in a form field, are there any workarounds?
irt.org | Knowledge Base | JavaScript | Form 2 | Q246 [ previous next ]
Q246 The onLoad event handler does not always set the focus in a form field, are there any workarounds?
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> |
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.