How can I make the first element of a form automatically receive keyboard focus when the form is loaded?Most form elements (i.e., text boxes, radio buttons, etc.) have a method called
focuswhich can be used just for this purpose. Simply add an
onLoadevent to your document's
<body>tag so that the
focusmethod is called when the form is loaded.
When the form is completely loaded, the
<body onLoad="document . loginform . username . focus ();"> Please identify yourself: <form name=loginform> <pre> username: <input name=username type=text> password: <input name=password type=password> <input type=submit value="OK"> </pre> </form> </body>
onLoadevent will fire, which in turn will give keyboard focus to the username element of the form.
April 16, 1997