Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onBlur global event

Status
Not open for further replies.

robdon

Programmer
May 21, 2001
252
ES
Hi,

While I'm running an Ajax query, I'm trying to disable the user from moving to other fields on the form.

So, I need a 'global' onBlur event to set focus back to the currect field which its running.

I've tried the following at the start of my code, where I define other global events (that work fine) like onClick & oncontextmenu...

document.onBlur = myBlurProc;

But it doesnt seem to fire on any of my controls.

Anyone know how I can dynamically attach a onBlur event to all of my fields.

Thanks,

Rob D.

ProIV Resource Centre
 
Anyone know how I can dynamically attach a onBlur event to all of my fields.

Yes - loop over all of the fields you want to attach the event to, and attach it to them one at a time.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Hi,

Thanks for that, but I dont really want to do that.

There has to be a global method, surely??

Really, looping through all elements and attaching an event isnt the best for performance, IMO.

Rob.

ProIV Resource Centre
 
You said:
I dont really want to do that.

That's odd, because it's exactly what you asked for:

You said:
Anyone know how I can dynamically attach a onBlur event to all of my fields.

You said:
There has to be a global method, surely??

Why does there have to be?

You said:
looping through all elements and attaching an event isnt the best for performance, IMO

How many elements are we talking here? Have you tried it? How long did it actually take? IMO, anything less than [picks an arbitrary number] 100, then it should take a fraction of a second.

AFAIK, there is no other way.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
why noy just include the on blur for each element in the html source code?
(if html is generated serverside it should still be possible to include it here.)
 
why noy just include the on blur for each element in the html source code?

Because it's considered bad practice to do so, not least because those without JS have to download extra bytes that having an external script file would negate.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top