469,133 Members | 1,404 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,133 developers. It's quick & easy.

Cancelling a pending onblur event

Hi All,

I have a web form which performs certain actions upon moving focus away
from a field. However, if the user clicks the top corner 'X' icon to
close the window, the onBlur event still fires. If, for example, the
onBlur event was an alert() popup: when the user clicks the close
window icon, the window closes and then the alert pops up. Clearly, if
the user closed the window, there is no point to performing the onBlur
event.

Is there any way to detect that an onBlur event is pending, then do
something in an onUnload handler to cancel that event? Perhaps there
is an event queue which can be manipulated?

Thanks in advance.

-Dave H.

Jul 23 '05 #1
5 7210

Paste what you have, http://nopaste.php-q.net/ , maybe you don't need
onblur and another event handler may do the job, I mean, is doable to
track the mouse coordinates and take it from there or other flagging, but
seems overkill.

Danny

On Thu, 23 Jun 2005 09:05:09 -0700, Dave Hammond <dh****@gmail.com> wrote:
Hi All,

I have a web form which performs certain actions upon moving focus away
from a field. However, if the user clicks the top corner 'X' icon to
close the window, the onBlur event still fires. If, for example, the
onBlur event was an alert() popup: when the user clicks the close
window icon, the window closes and then the alert pops up. Clearly, if
the user closed the window, there is no point to performing the onBlur
event.

Is there any way to detect that an onBlur event is pending, then do
something in an onUnload handler to cancel that event? Perhaps there
is an event queue which can be manipulated?

Thanks in advance.

-Dave H.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #2
Thanks for your reply. Changing the event handler isn't an option. The
application is a grid-style data editor which uses the onblur handler
to validate data whenever the user moves the cursor. using onchange
won't work because the validation needs to happen, even if the user
doesn't change the data (ie, leaving an empty field empty would not
trigger an onchange), and the data has to be validated in realtime, not
when they submit.

Jul 23 '05 #3

Then, use onunload on say, body:

document.body.onunload=function(){ YOUROBJHERE.onblur=null; }

Danny
On Thu, 23 Jun 2005 14:37:26 -0700, Dave Hammond <dh****@gmail.com> wrote:
Thanks for your reply. Changing the event handler isn't an option. The
application is a grid-style data editor which uses the onblur handler
to validate data whenever the user moves the cursor. using onchange
won't work because the validation needs to happen, even if the user
doesn't change the data (ie, leaving an empty field empty would not
trigger an onchange), and the data has to be validated in realtime, not
when they submit.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #4
On 23/06/2005 17:05, Dave Hammond wrote:

[snip]
Is there any way to detect that an onBlur event is pending, then do
something in an onUnload handler to cancel that event? [...]


No, because the blur event won't be pending: it will have been handled
already. You have the order of events confused.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
Jc
Dave Hammond wrote:
Thanks for your reply. Changing the event handler isn't an option. The
application is a grid-style data editor which uses the onblur handler
to validate data whenever the user moves the cursor. using onchange
won't work because the validation needs to happen, even if the user
doesn't change the data (ie, leaving an empty field empty would not
trigger an onchange), and the data has to be validated in realtime, not
when they submit.


You may want to consider using a different technique, which should
still satisfy your real-time requirement. For example, a technique I've
used before was to show static data until the user clicked on a cell,
which would "activate" the row, changing each cell into an editable
entity, such as a drop-down, editbox, etc. Once the user was done
editing that row, they could click the checkmark button at the
beginning of the row to submit the changes behind the scenes to the
server. Clicking on another row without submitting the changes would
prompt the user to either save or discard the changes.

I recommend avoiding onblur if you can (especially for input
validation), you will continue to run into these sort of issues, some
of which I haven't seen a workaround for, other than to simply not use
onblur for that particular purpose.

Another way to avoid using onblur is to detect when the user has
switched to a new cell, you can detect a TAB in onkeydown, and you can
detect a click in onclick, so you should be able to determine when they
have switched cells, as long as you maintain a little bit of state
information (eg. the active cell).

So simply putting focus on something validates it? Let's hope your
users don't accidentally hold down the TAB key.

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Gary | last post: by
1 post views Thread by Paul THompson | last post: by
1 post views Thread by Barry Svee | last post: by
2 posts views Thread by D. Alvarado | last post: by
2 posts views Thread by andyalean | last post: by
2 posts views Thread by Heiko Vainsalu | last post: by
1 post views Thread by neil S via DotNetMonster.com | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.