The onblur Event


The onblur Event

The onblur event occurs when an object loses the focus. (The idea is, if it's out of focus, it must be blurred). You can find the support for this event in Table 6.60.

Table 6.60. The onblur Event

Event

NS2

NS3

NS4

NS6

IE3a

IE3b

IE4

IE5

IE5.5

IE6

onblur

x

x

x

x

x

x

x

x

x

x

Here's an example that does a little data verification as the user enters numbers into a text field. If the user enters a value into the text field that is not a number (which we'll check with the isNaN function we saw in Chapter 2, "The JavaScript Language: Data, Operators, and Branching") and then clicks outside the text field, causing it to lose the focus, an alert box will appear with the message Please enter a number! :

(Listing 06-12.html on the web site)
 <HTML>      <HEAD>          <TITLE>Using the onblur Event</TITLE>          <SCRIPT LANGUAGE="JavaScript">              <!--  function checker()   {   if(isNaN(document.form1.text1.value)){   alert("Please enter a number!")   }   }  // -->          </SCRIPT>      </HEAD>      <BODY>          <H1>Using the onblur Event</H1>          <FORM NAME="form1">  <INPUT TYPE="TEXT" ID="text1" SIZE="50" ONBLUR="checker()"></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