Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: JavaScript
Expertise: Beginner
May 14, 1997



Application Security Testing: An Integral Part of DevOps

Bringing focus to a form element upon loading

Is it possible to bring focus to a particular form element, such as the first text area of a form, when the document loads? It must be, but for the forms I encounter, the focus is controlled manually by the user. I find this inconvenient! Focus should be automatic, leaving the user with only the task of tabbing between form elements.

Most form elements (text boxes, radio buttons, etc.) have a method called focus, which can be used just for this purpose. Simply add an onLoad event to your document's tag so that the focus method is called when the form is loaded.


The following source describes a log-in form that automatically places keyboard focus in the username field:
onLoad="document . loginform . username . focus ();">

Please identify yourself:

When the form is completely loaded, the tag's onLoad event will fire, which will give keyboard focus to the form's username element.
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date