Name

Input.focus( ) — give keyboard focus to a form element

Availability

JavaScript 1.0

Synopsis

                  input.focus(  )

Description

The focus( ) method of a form element transfers keyboard focus to that element without calling the onfocus event handler. That is, it makes the element active with respect to keyboard navigation and keyboard input. Thus, if you call focus( ) for a Text element, any text the user types appears in that text element. Or, if you call focus( ) for a Button element, the user can invoke that button from the keyboard.

All form elements except the Hidden element support the focus( ) method. Unfortunately, not all platforms support keyboard navigation equally well. In Unix versions of Netscape, focus( ) is functional only for those form elements that display text: Text, Textarea, Password, and FileUpload.

Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.