asp.net.ph

onblur Event

DHTML Events


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

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, Internet Explorer® supports 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

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.

<head>
<script language="JavaScript">
<!--
function leave(field){
alert ('The focus has just left the '+field+' field.')}
//—>
</script>
</head>

<body>
<div align="center">
<form><table>
<tr>
  <td>First Name</td>
  <td><input type="text" name="FirstName"
    onblur="leave(name)"></td></tr>
<tr>
  <td>Last Name</td>  
  <td><input type="text" name="LastName"
    onblur="leave(name)"></td></tr>
<tr>
  <td>Phone Number</td>
  <td><input type="text" name="PhoneNumber"
    onblur="leave(name)"></td></tr>
</table></form></div>
</body>

 Show me 

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.

Sample Code

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

BUTTON, INPUT, LABEL, SELECT, TEXTAREA, window

See Also

blur, focus, onchange, onclick, onfocus




Contents
HTML Elements
HTML Element Attributes
CSS Attributes
DOM Objects
DOM Object Properties
DOM Events Reference
DOM Methods Reference
DOM Collections Reference
 

Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

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

You can help support asp.net.ph