onblur Event

DHTML, HTML, & CSS

 
Click to return to the DHTML, HTML & CSS home page    
onbeforeupdate Event     onbounce Event     DHTML Events    

onblur Event


Fires when the object loses the input focus.

Syntax

Inline HTML<ELEMENT onblur = "handler" ... >All platforms
Event propertyobject.onblur = handlerJScript (compatible with ECMA 262 language specification) and VBScript
Named script<SCRIPT FOR = object EVENT = onblur>Internet Explorer only

Remarks

BubblesNo
CancelsNo
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.

Event Object Properties

clientXRetrieves the x-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars.
clientYRetrieves the y-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars.
offsetXRetrieves the horizontal coordinate of the mouse's position relative to the object firing the event.
offsetYRetrieves the vertical coordinate of the mouse's position relative to the object firing the event.
screenXRetrieves the horizontal position of the mouse, in pixels, relative to the user's screen.
screenYRetrieves the vertical position of the mouse, in pixels, relative to the user's screen.
srcElementRetrieves the object that fired the event.
typeRetrieves the event name from the event object.
xRetrieves the x-coordinate of the mouse cursor relative to the parent element.
yRetrieves 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 focus—that 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>

This feature requires Internet Explorer 4.0 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft Internet Explorer

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
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

blur, focus


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.