473,372 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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 misunderstanding 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 3065


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#Events-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.mozilla.org/buglist.cgi?query_format=advanced&short_desc_type= allwordssubstr&short_desc=focus+event+bubbl&produc t=Core&component=DOM&component=DOM+to+Text+Convers ion&component=DOM%3A+Abstract+Schemas&component=DO M%3A+Core&component=DOM%3A+CSSOM&component=DOM%3A+ Events&component=DOM%3A+HTML&component=DOM%3A+Leve l+0&component=DOM%3A+Load+and+Save&component=DOM%3 A+Mozilla+Extensions&component=DOM%3A+Traversal-Range&component=DOM%3A+Validation&component=DOM%3A +Views+and+Formatting&component=Event+Handling&lon g_desc_type=substring&long_desc=&bug_file_loc_type =allwordssubstr&bug_file_loc=&status_whiteboard_ty pe=allwordssubstr&status_whiteboard=&keywords_type =allwords&keywords=&emailassigned_to1=1&emailtype1 =exact&email1=&emailassigned_to2=1&emailreporter2= 1&emailqa_contact2=1&emailtype2=exact&email2=&bugi dtype=include&bug_id=&votes=&chfieldfrom=&chfieldt o=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+ sort+as+last+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*******@yahoo.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#Events-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
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...
4
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>...
5
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....
20
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...
6
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);...
7
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...
5
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...
2
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....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.