Solved

Identifying current active element

Posted on 2000-05-07
7
434 Views
Last Modified: 2008-03-10
How can a javascript function identify the current active element in a document?

for instance in the following code what should I put inplace of activeOBJ?

<HTML>
<BODY>
<FORM id="frm" action="something">
  <INPUT id="input1">
  <INPUT id="input2">
</FORM>
<SCRIPT type="text/javascript">
function handler(e);
{
  if (activeOBJ == "input1") {
    dosomething();
  }
}
document.onkeypress = handler;
</SCRIPT>
</BODY>
</HTML>
0
Comment
Question by:mehran
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
newjack earned 200 total points
ID: 2785680

I would do it like this :

Put the handler function in an event of the objects, e.g. the onClick, onChange event.
By doing that you can use the 'self' object in your handler function to reference the current object.

so to check the value you could use

function handler () {
  if (self.value == "x") {
    dosomething ();
  }
}
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2786608
Methinks you mean this and not self

Michel
0
 

Author Comment

by:mehran
ID: 2788920
event.srcElement.name was what I really look for.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2789738
Which is e.target.name in Netscape
0
 

Author Comment

by:mehran
ID: 2790080
thanks mplungjan, but I asked this question twice, once in html folder and other one in javascript folder.

and I got my answer in the other side(folder).
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2790092
No problem
0
 
LVL 3

Expert Comment

by:newjack
ID: 2790105

it is indeed this and not self, I happened to come across it myself today :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question