asp.net.ph

Skip Navigation Links

onblur Event


Fires when the object loses the input focus.

Syntax

Inline <element onblur = "handler" ... >
Script object.onblur = handler

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 occurs when an element loses focus either via the pointing device or by tabbing navigation.

This event is valid for the following elements: LABEL, INPUT, SELECT, TEXTAREA, and BUTTON, as well as the window object.

In addition, most current browsers support the event in any element that can receive the focus, such as links in anchors and area elements.

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.

The focus events are useful for determining when to prepare an object to receive or validate input from the user.

Event Object Properties

While event handlers in the Document Object Model do not receive parameters directly, the handler can query the event object for data.

Event Object Properties


Example

Often, onblur is used in form field validation. In the following example, userName is a required text field.

When a user attempts to leave the field, the onblur event calls a JavaScript function to confirm that userName has an acceptable value.

<input name="userName" onblur="validUserName(this.value)">

The example below demonstrates the use of the onblur event, to pass the name of the source element wherein the event occurs, to a function that simply displays which object has lost focus.

Sample Code

 Show me 

Applies To

BUTTON, INPUT, LABEL, SELECT, TEXTAREA, window

See Also

blur, focus, onchange, onclick, onfocus


Need a break ?
Suggested Reading

Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph.

If you have any question, comment or suggestion,
please send us a note