The focus Method


The focus Method

The 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

Method

NS2

NS3

NS4

NS6

IE3a

IE3b

IE4

IE5

IE5.5

IE6

focus()

x

x

x

x

x

x

x

x

x

x

 

No return value

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> 


Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net