onblur

HTML (DHTML)

onblur Event

Internet Development Index

Fires when the object loses the input focus.

Syntax

Inline HTML<ELEMENT onblur = "handler" ... > All platforms
Event propertyobject.onblur = handlerJScript only
object.onblur = GetRef("handler")Visual Basic Scripting Edition (VBScript) 5.0 or later only
Named script <SCRIPT FOR = object EVENT = onblur> Internet Explorer only

Event Information

BubblesNo
CancelsNo
To invoke
  • 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.

Event Object Properties

Although event handlers in the DHTML Object Model do not receive parameters directly, a handler can query an event object for data.

Available Properties

altKey Sets or retrieves a value that indicates the state of the ALT key.
altLeft Sets or retrieves a value that indicates the state of the left ALT key.
clientX Sets or retrieves the x-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.
clientY Sets or retrieves the y-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.
ctrlLeft Sets or retrieves the state of the left CTRL key.
offsetX Sets or retrieves the x-coordinate of the mouse pointer's position relative to the object firing the event.
offsetY Sets or retrieves the y-coordinate of the mouse pointer's position relative to the object firing the event.
screenX Retrieves the x-coordinate of the mouse pointer's position relative to the user's screen.
screenY Sets or retrieves the y-coordinate of the mouse pointer's position relative to the user's screen.
shiftLeft Retrieves the state of the left SHIFT key.
srcElement Sets or retrieves the object that fired the event.
type Sets or retrieves the event name from the event object.
x Sets or retrieves the x-coordinate, in pixels, of the mouse pointer's position relative to a relatively positioned parent element.
y Sets or retrieves the y-coordinate, in pixels, of the mouse pointer's position relative to a relatively positioned parent element.

Remarks

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.

For Internet Explorer 5 and later, the onblur event is asynchronous.

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 Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

Standards Information

This event is defined in HTML 4.0 Non-Microsoft link.

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

blur, focus, onfocusout