470,638 Members | 1,581 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,638 developers. It's quick & easy.

Checking for focus

Hello,
is there a function with which I can find out if a form element has the
focus?
Something like:

function ReactIfFocus()
{
for(var i=0; i<10; i++)
if( HasFocus(document.forms[0].elements[i])
makeSomething();
}

I need the function to move the focus to the next field.

Thanks
Christoph
Jul 23 '05 #1
3 2765


Christoph Weber wrote:
is there a function with which I can find out if a form element has the
focus?
Something like:

function ReactIfFocus()
{
for(var i=0; i<10; i++)
if( HasFocus(document.forms[0].elements[i])
makeSomething();
}

I need the function to move the focus to the next field.


There are event handlers onfocus and onblur that let you react to a
change of focus.
IE also has
if (document.activeElement == document.forms[0].elements[i])
see
http://msdn.microsoft.com/library/de...iveelement.asp

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
Danke !!
So geht es.
Jul 23 '05 #3
"Christoph Weber" <ch*************@im-achental.de> wrote in message news:<2g**********@uni-berlin.de>...
Hello,
is there a function with which I can find out if a form element has the
focus?
Something like:

function ReactIfFocus()
{
for(var i=0; i<10; i++)
if( HasFocus(document.forms[0].elements[i])
makeSomething();
}

I need the function to move the focus to the next field.

Thanks
Christoph

I did some quick Googling, and couldn't find anything like that.
What are you trying to do? The only suggestion I found is to
keep track of it or fire the desired function on the onfocus event.

Shawn
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Philip D Heady | last post: by
10 posts views Thread by Samir | last post: by
1 post views Thread by roN | last post: by
125 posts views Thread by jacob navia | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.