Which element has focus
Hi everybody,
Is there a way to find out whitch element has focus on DHTML form with javascript?
Thanks
Igor
[120 byte] By [
Igor] at [2007-11-9 16:16:53]

# 1 Re: Which element has focus
Igor,
You can use (and modify) this JavaScript for your needs.
function testForFocus()
{
if (document.myForm.myTxtBox.gotfocus = true)
{
alert("Text box has focus!")
}
}
This script is assuming the form name is "myForm" and the text type input is
named "myTxtBox".
Michael Sanchez
Runtime Web Development
"Igor" <irodionov@hotmail.com> wrote in message
news:3e9b2be5$1@tnews.web.dev-archive.com...
>
> Hi everybody,
> Is there a way to find out whitch element has focus on DHTML form with
javascript?
> Thanks
> Igor
# 2 Re: Which element has focus
Here's another approach that doesn't care about the element.
function getElementWithFocus()
{
var rtnValue = null;
for(var i=0;i<document.all.length;i++)
{
try
{
if ( document.all.items[i].gotFocus )
{
// assume that element has name and/or id.
alert( document.all.item[i].name + ' has focus!');
rtnValue = document.all.items[i];
break;
}
}
catch (ex)
{
// catch exception for when the element doesn't support the gotFocus
attribute.
}
return rtnValue;
}
}
--
Regards,
Tim Ellison, MCP
Whitlock eBusiness Solutions
(w) 804-794-2871 x144
(m) 804-405-4874
"Igor" <irodionov@hotmail.com> wrote in message
news:3e9b2be5$1@tnews.web.dev-archive.com...
>
> Hi everybody,
> Is there a way to find out whitch element has focus on DHTML form with
javascript?
> Thanks
> Igor