473,722 Members | 2,147 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 7591

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.c om> 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.o nunload=functio n(){ YOUROBJHERE.onb lur=null; }

Danny
On Thu, 23 Jun 2005 14:37:26 -0700, Dave Hammond <dh****@gmail.c om> 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
11382
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 browser) SQL Server continues to process the request, which usually renders the server unresponsive...
1
1881
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 cancel the onkeypress fine in NN. The TAB fires the onkeydown in IE and can be cancelled in IE. ...
1
16599
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 gain focus and then immediately lose focus (blur) to the first field, button, or whatever that is...
2
3720
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" function is invoked. And on Mozilla Filefox 0.9.1, the event never launches even when I leave the...
4
7600
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
11448
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
5686
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
5679
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 type ahead/autocomplete thingy. All this works fine. Here's my problem: I wanted to expose the...
2
4706
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 also attach event handlers to 'onblur' events eg: 'window.blur=f3()'
0
8739
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9088
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8052
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5995
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4502
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.