The onblur EventThe 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
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> |