Click here to Skip to main content
15,904,351 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want to understand exactly what is onblur event in javascript.

In my project most of the places its used in this way

txtEmployeeID.Attributes.Add("onblur", "fnGetEmployeeName();");


I tried to google . But the answer i m getting is like "The onblur attribute fires the moment that the element loses focus."


I am unable to understand this. kindly help.
Posted

The "onblur" event fires when the current control no longer has the cursor inside of it. So if you type something in the textbox and click something else, the "onblur" event fires because the cursor is not focused on that control anymore

See this[^]
 
Share this answer
 
Comments
anurag19289 24-Oct-13 12:28pm    
Got it :)
In a windows forms application the equivalent event would be something like OnLostFocus. The event fires between leaving txtEmployeeID and just before the next control will get the focus. You could use it to color the edit box red in case someone entered an invalid value for example.

Hopefully that makes it somewhat more clear.

Good luck!
 
Share this answer
 
v2
Comments
anurag19289 24-Oct-13 12:28pm    
Thanks :)
The onblur event in javascript will execute when the user click out side the control after clicking inside.Here you are applying the onblur event to the textbox named txtEmployeeID and assigning the particular method for executing when the onblur event occurs and this event will execute when you click outside the textbox txtEmployeeID only after clicking the mouse pointer in to it. And remember that it will execute only once after leaving the the textbox. If you have to execute it again you have to click in side the textbox.
 
Share this answer
 
v2
Comments
anurag19289 24-Oct-13 12:28pm    
Thank you :)
Too understand blur event first you need to understand focus event.

Focus event is fired when a specific control gets focus. Consider a text box in html. When some one click on text box, focus event is generated for that text box. Now all the subsequent keyboard will go to that text box only.

Now consider, you have focus on text box and you pressed tab. It will change the focus to next control of page. So text box looses its focus. And so its blur event will be generated. So you can say that blur will be generated when a control looses focus. And when text box looses focus, cursor within it gets hidden, and you no longer able to type.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900