Fires when the object loses the input focus.
Syntax
Inline HTML <ELEMENT onblur = "handler" ... > All platforms Event property object.onblur = handler JScript (compatible with ECMA 262 language specification) and VBScript Named script <SCRIPT FOR = object EVENT = onblur> Internet Explorer only
Remarks
Bubbles No Cancels No To invoke Cause an object to lose focus:
- Click the mouse on the document background or another control.
- Use the keyboard to navigate from one object to the next.
- Invoke the blur method when an object has focus.
- Switch focus to a different application or open a second browser window.
Default action Switches focus away from the object on which the event is fired. The onblur event fires on the original object before the onfocus or onclick event fires on the object that is receiving focus. Where applicable, the onblur event fires after the onchange event.
Use the focus events to determine when to prepare an object to receive or validate input from the user.
As of Microsoft® Internet Explorer 5, you must set the TABINDEX attribute of elements that expose the onblur event.
Event Object Properties
Although event handlers in the document object model do not receive parameters directly, the handler can query the event object for data.
clientX Retrieves the x-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars. clientY Retrieves the y-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars. offsetX Retrieves the horizontal coordinate of the mouse's position relative to the object firing the event. offsetY Retrieves the vertical coordinate of the mouse's position relative to the object firing the event. screenX Retrieves the horizontal position of the mouse, in pixels, relative to the user's screen. screenY Retrieves the vertical position of the mouse, in pixels, relative to the user's screen. srcElement Retrieves the object that fired the event. type Retrieves the event name from the event object. x Retrieves the x-coordinate of the mouse cursor relative to the parent element. y Retrieves the y-coordinate of the mouse cursor relative to the parent element.
Example
This example shows how to display the name of the object that has lost focusthat is, the object that fires the onblur event.
<HTML> <BODY> <INPUT TYPE=text NAME=txtFName VALUE="First Name" onblur="alert(event.srcElement.name)"> <INPUT TYPE=text NAME=txtLName VALUE="Last Name" onblur="alert(event.srcElement.name)"> <INPUT TYPE=text NAME=txtPhone VALUE="Phone" onblur="alert(event.srcElement.name)"> </BODY> </HTML>
Applies To
A, ACRONYM, ADDRESS, APPLET, AREA, B, BDO, BIG, BLOCKQUOTE, BUTTON, CAPTION, CENTER, CITE, custom, DD, DEL, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, FRAME, FRAMESET, Hn, HR, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, INS, ISINDEX, KBD, LABEL, LEGEND, LI, LISTING, MARQUEE, MENU, OBJECT, OL, P, PLAINTEXT, PRE, Q, RT, RUBY, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, window, XMP
See Also