JavaScript blur event
When any text box, text area or select box looses its focus then the blur event occurs. The onBlur event handler can execute the specific JavaScript code on the invocation of a blur event. To explain this onBlur event handler, we have created a simple example here which will provide you the clear understanding of blur event.
Explanation with code :
In this example we have created three text boxes for First name, Middle name and Last name and as soon as we lost focus from the text box, onBlur() event occurs and specified function or methods is invoked. Here we have created three function which are invoked on the blur event of the given three input text boxes.
|
Function addFName() is called on the blur event of first text box ( first name), function addMName() is called on the blur event of the second text field (middle name) and addLName() function is called on blur event of third text field ( last name ).
| <input type="text" value="" id="fname" onBlur=addFName()> |
As you can see from the above code that we have invoked the addFName() method on the blur event Here is the full source code as follows :
<html> |
Output :

As soon as we lost focus from the very first text box it calls the "onBlur" event and an alert message floats showing "First name blurred" message.

As we click on the "Ok" button of alert message box it writes text into the first text box and focus goes on the second text box.
As we move the focus from the second text box it again floats an alert message.



You can also download source code from the following link :
Tutorials
- Java 26 (JDK 26) Features with examples
- Top 10 Reasons to Learn Java in 2026
- JDK 26 Tutorial
- Java Certification Roadmap 2026: Which Oracle Certs Matter
- Install JDK 26: A Complete Beginner's Guide (2026)
- What Is Java? A Complete, Up-to-Date Guide for 2026
- Java 26 HTTP3 tutorial - HTTP 3 support in JDK 26 - How to use HTTP/3 in Java 26 application?
- JDK 28 Preview: Value Objects, Shenandoah GC & JSON API
- Java Tutorials


