Text.focus()

JavaScript1.0+, JScript1.0+ Nav2+, IE3+, Opera3+ Syntax

							text.focus()

Description

The focus() method of the Text object gives focus to the text box. Be careful when using this method in conjunction with the Text.blur() method. It can lead to a focus/blur loop, where the browser blurs a focus as soon as it is done, and vice versa.

Example

Listing 7.495 has two text boxes and two buttons. If the user clicks the first button, the cursor is set inside the first text box. If the user clicks the second text box, the cursor is set inside the second text box.

Listing 7.495 Using the focus() Method to Place the Cursor in the Desired Text Box
 <html> <head> <script language="JavaScript"> <!-- Hide // Define the setFocus function called ...

Get Pure JavaScript 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.