Solved

Identifying current active element

Posted on 2000-05-07
7
424 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
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
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 …
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…

772 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