473,789 Members | 2,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OnBlur() focus problems

I have a textarea element that I have created an onblur() handler for.

In the onblur() handler, I check to make sure that they have saved the
contents of the edit box, before leaving it.

If they have not saved the contents, when they exit the edit box, I put up
an alert telling them to perform the save.

My handler (note: the editBox variable was properly assigned a reference to
the desired HTML textarea element earlier):

function onEditBoxBlur()
{
if (bNotSaved)
{
alert("Please save your new text.");
editBox.focus() ;
return false;
}
return true;
}

However, after they hit OK to the alert box, focus ends up in a textarea
element *below* the desired edit box (the one has the onEditBoxBlur() as
it's "onblur" handler).

If I remove the editBox.focus() statement, then focus returns to the web
page itself instead.

Why is this happening and how can I fix things so that focus returns to the
desired textarea control ("editBox")?

Thanks.

Aug 25 '05 #1
3 8927
Are you sure you have the correct element when setting the focus?

Aug 25 '05 #2

"Xandax" <xa****@gmail.c om> wrote in message
news:11******** ************@z1 4g2000cwz.googl egroups.com...
Are you sure you have the correct element when setting the focus?


Xandax,

Yes. I know this because I use the same variable that contains the element
node reference, to set the focus to that element when the page first starts
up.

Thanks.
Aug 25 '05 #3
Robert Oschler said the following on 8/25/2005 3:41 AM:
I have a textarea element that I have created an onblur() handler for.
onblur is a bad idea.
In the onblur() handler, I check to make sure that they have saved the
contents of the edit box, before leaving it.
How do they save the contents without blurring the text box? If they
have to leave the box to save it, then your onblur gets fired, but thats
a drawback of the onblur. Consider onChange instead.
If they have not saved the contents, when they exit the edit box, I put up
an alert telling them to perform the save.

My handler (note: the editBox variable was properly assigned a reference to
the desired HTML textarea element earlier):
How is it defined and assigned though? That may very well be the
problem, but without seeing the code that assigns it.....
function onEditBoxBlur()
{
if (bNotSaved)
{
alert("Please save your new text.");
editBox.focus() ;
return false;
}
return true;
}

However, after they hit OK to the alert box, focus ends up in a textarea
element *below* the desired edit box (the one has the onEditBoxBlur() as
it's "onblur" handler).


That indicates that your editBox variable is not assigned to the correct
textArea.

Or, that bNotSaved is not defined properly.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 25 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4276
by: Bartosz Wegrzyn | last post by:
I do validate my form using onblur() event. In my example I have 3 fields in my form. name,address and city. I call my functions using onblur()="isname(this)" ...etc. My probllem is that when I fill the form fields everything is fine. When I dont I have a problem. When I leave empty field for lets say name the the isname() function is called and tells my to enter the data. It tries to focus on that field and select it. The problem is...
2
13076
by: Bartosz Wegrzyn | last post by:
I use onblue event to validate fields in my form. I do this onblur="return isname()" and so so ... I have one form with 20 fields. My problem is that when the focus is for example on the first field of my form the "name" field and I click somewher or press tab than I loose focus and my isname() function is executed. Everything is fine but the focus was change for next field
1
16603
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...
1
20277
by: Rich Morey | last post by:
Hello, I have created a form and assigned each of the form elements to a class in a style sheet. I would like to know if it is possible to add 'OnFocus' and 'OnBlur' events to the style sheet class so that I can change the background color of a form element WITHOUT having to add 'OnFocus' and 'OnBlur' events to each individual form element..
9
3714
by: Roger Withnell | last post by:
Tearing hair out time! Simple attached page shows the problem. http://www.brilley.co.uk/TestFocusSelect.htm Using a function to test if too many characters have been keyed in to a textarea. Obviously, must return focus and select to the textarea if too many have been keyed. When the function is called with onblur, it works in IE but not in Safari or NN. The function is called but the focus() and select() methods fail.
1
11308
by: Christoph | last post by:
I'm trying to validate some HTML form elements when the user tabs out of each element. However, I'm having some problems. It appears that the order of events is onChange followed some time afterwards by onBlur. I believe this to be the case because in my onChange script, if the validation fails, I force focus back to the field element. However, the focus still falls to the next field and not back to the field I tried to force the...
2
3732
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...
10
2461
by: John Kotuby | last post by:
Hello all... I am working on an ASP.NET 2.0 application with VS2005 and VB. I have chosen to use popup windows in some cases because it makes the user experience better (according to all the users I have polled who will be using this app). In an attempt to keep the popup from disappearing behind the calling window, I am adding the onblur="FocusMe():" event to the Body tag of the popup. I really want onblur to react to any click outside...
0
9663
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10195
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
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...
1
7525
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6765
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
5415
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...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
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
3
2906
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.