Add event handler for input text element onblur event in JavaScript

Description

The following code shows how to add event handler for input text element onblur event.

Example


<!--  ww w.  jav a 2  s. c om-->
<html>
<head>
<title></title>
<script type="text/javascript">
window.onload=setObjects;

function setObjects() {
document.personData.firstName.onblur=testValue;
}

function testValue() {
document.write(this.value);
}
</script>
</head>
<body>
<form name="personData">
First Name: <input type="text" name="firstName" />
</form>
</body>
</html>

Click to view the demo

The code above generates the following result.

Add event handler for input text element onblur event in JavaScript
Home »
  Javascript Tutorial »
    Event »
      Focus Event
Javascript Tutorial Focus Event
Add event handler for input text element on...
Add event listener to input text focus on e...
Listen to Focus Lost event for input passwo...