Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding which item has the focus

Status
Not open for further replies.

anto2

Programmer
Apr 4, 2001
29
IE
Hello,

I there a way to find which item has the focus in javascript.

Anthony
 
Since the document knows which object has Focus already, you just need to add an onFocus handler to form elements, images, and/or links. Now when something on the page gets the focus it will call a javascript function and can even send information to that function as in the simple example below:

<html>
<head>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
function whichOne(fName) {
alert(fName)
}
</script>
</head>

<body>
<form name=&quot;form1&quot;>
<input type=&quot;text&quot; name=&quot;text1&quot; onFocus=&quot;whichOne('The Focus is on form1.text1')&quot;><br>
<input type=&quot;text&quot; name=&quot;text2&quot; onFocus=&quot;whichOne('The Focus is on form1.text2')&quot;><br>
<input type=&quot;text&quot; name=&quot;text3&quot; onFocus=&quot;whichOne('The Focus is on form1.text3')&quot;><br>
<input type=&quot;text&quot; name=&quot;text4&quot; onFocus=&quot;whichOne('The Focus is on form1.text4')&quot;>
</form>
</body>
</html>
 
Thanks LAwebTek,

I thought that might be the ony way but I was hoping there was some page property that would tell me this as our application is pretty much finished.

Anthony.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top