473,513 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7567

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
11368
by: Gary | last post by:
I'm using ASP (VB Script) to generate some reports from a SQL Server database. These queries often take a significant amount of time to complete, and many of these reports consist of multiple queries. One of the biggest problems end users have with this is that if the report generation is cancelled (e.g. hitting the stop button on the...
1
1858
by: Paul THompson | last post by:
I have been working for some time to 1) detect tab and shift tab events 2) control the focus on the basis of these events. I have found that I can do this, but continue to have nagging problems. One of the main problems at this point lies in cancelling the event. I have found that the TAB fires the onkeypress in NN, but not in IE. I can...
1
16545
by: Barry Svee | last post by:
I'm struggling with the JavaScript blur event. I have an activex control that I need to interact with when a window loses focus, namely to instruct it to give up control of a barcode scanner so that the application being brought foreward can take control. It has been my observation that when I set the window.onblur function, the window will...
2
3698
by: D. Alvarado | last post by:
Hi, I'm having some trouble with the "onBlur" event in the BODY tag. Ideally, what I want to happen is that when someone leaves window A, window A executes a command. I had put <body onBlur="savePage();"> I have a couple of problems. On IE 6 (win2000), whenever I put the cursor focus on a textfield within window A, the "savePage"...
4
7546
by: Peloux | last post by:
Hi, I have written some htc in order to validate data in a form. most of htc are attached on 'onblur' event. Now, we would like to use the Enter Key to sublit form, so we use the following code : ----------- <SCRIPT> function touche_EnterKeyPress(){
2
11396
by: andyalean | last post by:
Hello javascript coders :( ,I am trying to add an onblur event to my code. This is where I dynamically create a textfield.I want to assign it an onblur event handler like so.How do I add a event to a newly created option text field.Thanks :D for( ;k < holdHalfHours; k++ ){ timeLog.appendChild(br); l = k +1;
2
5664
by: Heiko Vainsalu | last post by:
Hi Hope somebody knows how to solve this one. *The Situation* A traditional situation where HTML form inputs are checked... (if simplified then it would look something like this) <form onSubmit="return checkWholeForm(this)">
1
5655
by: neil S via DotNetMonster.com | last post by:
I have a custom control with a textbox and dropdown list. The dropdown list is hidden and acts as a data source for the textbox. When the user enters text in the textbox, an onKeyup event is fired and retrieves the first value from the dropdown list equal to that entered, and fills the text box. Essentially, the two together are acting as a...
2
4667
by: wolverine | last post by:
Hi All, In Mozilla Firefox, to onblur and onfocus event of each and every html element, the browser itself will attach a native event handler. I mean if you type, 'javascript:alert(window.blur)' in the address bar of Firefox browser, you can see a 'function ....' . That is a Firefox browser defined handler. Now assume that web developer...
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7565
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.