Solved

Identifying current active element

Posted on 2000-05-07
7
420 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
newjack earned 200 total points
Comment Utility

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
Comment Utility
Methinks you mean this and not self

Michel
0
 

Author Comment

by:mehran
Comment Utility
event.srcElement.name was what I really look for.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
Which is e.target.name in Netscape
0
 

Author Comment

by:mehran
Comment Utility
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
Comment Utility
No problem
0
 
LVL 3

Expert Comment

by:newjack
Comment Utility

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now