The focus MethodThe focus method gives an object the focus. You can see the support for this method in Table 6.20. Table 6.20. The focus Method
Here's an example. When you click a button, the button gets the focus. However, suppose that button spell-checks the text in a text fieldin that case, it would useful to transfer the focus back to the text field so that the user could just keep typing. Here's an example that does that: (Listing 06-06.html on the web site)<HTML> <HEAD> <TITLE>Using the focus Method</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function defocus() { document.form1.text1.focus() } // --> </SCRIPT> </HEAD> <BODY> <H1>Using the focus Method</H1> <FORM NAME="form1"> <INPUT TYPE="TEXT" ID="text1"></INPUT> <INPUT TYPE="BUTTON" ONCLICK="defocus()" VALUE="Click Me"></INPUT> </FORM> </BODY> </HTML> |