473,735 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem tracking focus of text input elements (Mozilla?)


Hi all.

Hopefully this should demonstrate the problem I'm having:

http://flooble.net/~pete/focus-problem-demo/

(I'm testing it in Mozilla only, but I'm not sure if it's actually a
Mozilla-only problem)

I'm capturing the focus and blur events for the document, updating a
global Javascript variable to keep track of the "currently focussed"
element.

The problem is that it just doesn't seem to work for text (or
textarea) input elements. Just about anything else, no problem, but
not text or textarea.

You can see by switching focus (eg. by tabbing) through the five input
elements. Entering/leaving the button, checkbox or select elements
generates a focus/blur event. Entering/leaving the text/textarea
elements generates absolutely nothing.

Can anyone suggest what's wrong with this picture? :) Is it a browser
bug or am I fundamentally misunderstandin g something about tracking
element focus?
Any help greatly appreciated. :)

Pete.

PS. I'd just like to mention that tracking focus bugs is hell when
just about everything you do changes the focus. :)
--
http://akira.apana.org.au/~pete/
"Reader, beware: This section is highly mathematical. Well, maybe not
_highly_ mathematical, but it's got a bunch of symbols and scary-looking
formulas. You have been warned." -- sci.crypt FAQ
Jul 23 '05 #1
2 3108


Peter Wright wrote:

Hopefully this should demonstrate the problem I'm having:

http://flooble.net/~pete/focus-problem-demo/

(I'm testing it in Mozilla only, but I'm not sure if it's actually a
Mozilla-only problem)

I'm capturing the focus and blur events for the document, updating a
global Javascript variable to keep track of the "currently focussed"
element.

The problem is that it just doesn't seem to work for text (or
textarea) input elements. Just about anything else, no problem, but
not text or textarea.


If you look at the W3C DOM Events specification here
<http://www.w3.org/TR/DOM-Level-2-Events/events.html#Eve nts-eventgroupings-htmlevents>
then it says about the focus event:

focus
The focus event occurs when an element receives focus either via a
pointing device or by tabbing navigation. This event is valid for the
following elements: LABEL, INPUT, SELECT, TEXTAREA, and BUTTON.

* Bubbles: No
* Cancelable: No
* Context Info: None

so the focus event is not supposed to bubble up the DOM tree and
therefore if you only look for focus events at the document or window
level then you are not supposed to see anything if focus is set on an
input or a textarea or a button. The event is fired on the target and
that is all that is supposed to happen. As far as I test here the focus
event is properly fired on the controls, it just doesn't bubble which it
is not supposed to do.
So the bug in Mozilla is more likely that for some controls the focus
event bubbles while it shouldn't. There are open bugs on that:
<https://bugzilla.mozill a.org/buglist.cgi?que ry_format=advan ced&short_desc_ type=allwordssu bstr&short_desc =focus+event+bu bbl&product=Cor e&component=DOM &component=DOM+ to+Text+Convers ion&component=D OM%3A+Abstract+ Schemas&compone nt=DOM%3A+Core& component=DOM%3 A+CSSOM&compone nt=DOM%3A+Event s&component=DOM %3A+HTML&compon ent=DOM%3A+Leve l+0&component=D OM%3A+Load+and+ Save&component= DOM%3A+Mozilla+ Extensions&comp onent=DOM%3A+Tr aversal-Range&component =DOM%3A+Validat ion&component=D OM%3A+Views+and +Formatting&com ponent=Event+Ha ndling&long_des c_type=substrin g&long_desc=&bu g_file_loc_type =allwordssubstr &bug_file_loc=& status_whiteboa rd_type=allword ssubstr&status_ whiteboard=&key words_type=allw ords&keywords=& emailassigned_t o1=1&emailtype1 =exact&email1=& emailassigned_t o2=1&emailrepor ter2=1&emailqa_ contact2=1&emai ltype2=exact&em ail2=&bugidtype =include&bug_id =&votes=&chfiel dfrom=&chfieldt o=Now&chfieldva lue=&cmdtype=do it&order=Reuse+ same+sort+as+la st+time&field0-0-0=noop&type0-0-0=noop&value0-0-0=>


--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Martin Honnen <ma*******@yaho o.de> wrote:
Peter Wright wrote:
http://flooble.net/~pete/focus-problem-demo/

(I'm testing it in Mozilla only, but I'm not sure if it's actually a
Mozilla-only problem)
[ snip ] If you look at the W3C DOM Events specification here
<http://www.w3.org/TR/DOM-Level-2-Events/events.html#Eve nts-eventgroupings-htmlevents>
then it says about the focus event:

focus
The focus event occurs when an element receives focus either
via a pointing device or by tabbing navigation. This event is valid
for the following elements: LABEL, INPUT, SELECT, TEXTAREA, and
BUTTON.

* Bubbles: No
Ahaaaaaa...

I should really check the official DOM documentation more often.
* Cancelable: No
* Context Info: None

so the focus event is not supposed to bubble up the DOM tree and
therefore if you only look for focus events at the document or window
level then you are not supposed to see anything if focus is set on an
input or a textarea or a button.
Okay, that does help to explain things... I was going nuts with this,
assuming that it was _supposed_ to bubble. Dammit.
The event is fired on the target and that is all that is supposed to
happen. As far as I test here the focus event is properly fired on
the controls, it just doesn't bubble which it is not supposed to do.
Argh. *sigh*

I was hoping to use this technique to track the current focus - I
guess it'll only work (for some value of "work") if I specifically set
the "focus" event handler to every single element in the display.

Ah well, I guess that'll be an acceptable solution. Sort of. :)
So the bug in Mozilla is more likely that for some controls the focus
event bubbles while it shouldn't. There are open bugs on that: [ snip open bugs ]

Thanks for your help Martin, I appreciate it.
Martin Honnen
http://JavaScript.FAQTs.com/


Pete.
--
http://akira.apana.org.au/~pete/
"What is a 'broken killfile'? One that only wounds messages rather
than killing them?" -- Craig Dickson
Jul 23 '05 #3

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

Similar topics

2
5085
by: Bettina | last post by:
I have a text field and I want that after I enter a text in this text field, the focus goes to the button.gif. How can I do it? Any ideas? I know that when you use an input type="submit", the focus goes automatically to the button, but I don't want to use a button. See please the piece of code: <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html;
4
2401
by: Scott Navarre | last post by:
Hi, I have Red Hat 8.0 and have the default Mozilla browser that comes with it. I am programming in javascript and have come across something problematic. Given the following code: <HTML> <HEAD> </HEAD> <BODY> <FORM>
5
10457
by: Mikko Rantalainen | last post by:
See example at <URL:http://www.cc.jyu.fi/~mira/moz/formtest.php>. The problem is that the label of submit button is always centered on the button regardsless of 'text-align' property in CSS. Considering that I can style everything else, this must be a bug, right? Any suggestions how to fix the issue with Mozilla 1.4? How about other versions of Mozilla? How about other browsers? (I'm aware that some people think that one should never...
20
12302
by: Arne | last post by:
During testing <div style="overflow:auto;"> in CSS I noticed the mousewheel would work in Mozilla only after I made a <a href="#">some text</a> link and clicked on that, within the div. It appears as if Mozilla needs to have the focus set on that div in order for the mousewheel to work. That's all that link does. The mousewheel works perfectly in IE without the link. It scrolls the div even if there is a scrollbar on the page. Is...
6
2026
by: joe | last post by:
Hi Everyone, could anyone comment on the following problem: I have a textbox being appended to a cell in a table, and am trying to call focus() on like this: <snip> c01.removeChild(answerbox); answerbox=document.createElement('input'); answerbox.addEventListener("change",check_answer,false); answerbox.style.fontSize=FONTSIZE; answerbox.style.backgroundColor=COLOR_ANSWBG;
7
20370
by: jerrygarciuh | last post by:
Hello, I have been playing with various Googled solutions for capturing the <Enter> key to suppress form submission. My first question is whether anyone has a script that works in all common browsers? The script bellow is IE only. It fails FF 1.0 and NN 7. Also, if I can trap the keypress I would like to use it to tab to the next tabindex.
5
8736
by: linuxnooby | last post by:
This is a simple question but it is doing my head in all i want is a form text field to be focused when the page loads. Works in IE6 but not in Firefox 1.6 <body > <form action="testfocus.htm" method="post" name="test" id="test" > <input type="text" name="name" id="name" onLoad="this.forms.elements.focus()"> <input type="submit" name="submit">
2
55382
by: yawnmoth | last post by:
Say I have two input elements and that I wanted to make it so that when the first ones input was what it should be, the focus would automatically be shifted to the next input element. ie. something like... <input onkeyup="if (this.value.length == this.maxlength) document.forms.elements.focus()" value="whatever" maxvalue="x" type="text" /> <input value="whatever" maxvalue="x" type="text" />
0
8965
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
9466
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...
0
9330
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...
1
9255
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
9202
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
4567
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
4823
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3278
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
2191
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.