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
- Clear cookie example
- JavaScript getElementById innerHTML
- JavaScript getElementById Style
- Javascript Examples
- JavaScript add row dynamically to table
- New Page 1
- JavaScript Change link
- JavaScript Checkbox getElementById
- javascript clear textarea
- JavaScript Clock Timer
- JavaScript Cookies
- JavaScript Date Difference
- JavaScript duplicate string
- JavaScript Email Validation
- javascript focus input
- JavaScript get excel file data
- JavaScript getAttribute Href
- JavaScript getAttribute Style
- JavaScript getElementById div
- JavaScript getElementById Iframe
- JavaScript getElementById select
- JavaScript Hide Button
- JavaScript Hide Div
- JavaScript hide image
- JavaScript Hide Table Column
- JavaScript Hide Table Rows
- JavaScript Key Event
- JavaScript link
- JavaScript method location
- JavaScript move div
- JavaScript move file
- JavaScript move image
- JavaScript Navigate Back
- JavaScript navigate to page
- JavaScript Navigate to URL
- JavaScript indexOf substring
- JavaScript onkeypress event
- JavaScript Open file
- JavaScript Open link in new window
- JavaScript Open Modal Window