Solved

Capture element name

Posted on 2003-12-02
9
447 Views
Last Modified: 2012-06-22
I have a link for example
<a href="" onClick="">Report problem</a>

After it is clicked I want to capture the name of the element that is clicked.

Does it make sense?

click link -> record next element clicked

Really what I want o do is, enable users to report am issue they are having with a textfield/dropdown etc.
I do not want to create an event on every object/element either, there are to many!
0
Comment
Question by:Tacobell777
9 Comments
 
LVL 5

Expert Comment

by:ho_alan
ID: 9863790
not really get your meaning
you want to get the name, location-href or the text between "<a></a>"??

<html>
<script>
list = new Array(10)
cnt = 0
</script>
<body>
<a name=a1 href="#" onclick="list[cnt++]=this.name;">link 1</a>
<br>
<a name=a2 href="#" onclick="list[cnt++]=this.name;">link 2</a>
<br>
<a name=a3 href="#" onclick="list[cnt++]=this.name;">link 3</a>
</body>
</html>

if you want to capture name, u use "this.name"
location href --> u use "this.href"
text btw "<a></a>" ---> u use "this.innerHTML"
hope this can inspire u
0
 
LVL 17

Author Comment

by:Tacobell777
ID: 9863860
Like I said "I do not want to create an event on every object/element either, there are to many!"

I want ONE link, when it is clicked I want to capture the object that is clicked after that.

So
1. Capturing is off
2. Link is clicked JS will be ready to capture
3. The user clicks anywhere in the document and whatever element/object is clicked will be captured

0
 
LVL 31

Accepted Solution

by:
GwynforWeb earned 125 total points
ID: 9864185
<html>
<head>
<script language="JavaScript">
function trace()
{
alert(document.activeElement.name+" is in focus");  
}
</script>
</head>

<body>

<form>
  <p><input type="button" value="trace next" name="abc" onblur="trace()"> </p>
</form>

<form name="f1">
  <p><input type="input" size="70" name="t1"> </p>
  <p><input type="button" value="click me" name="b1"></p>
  <p><textarea name="t1" rows="1" cols="20"></textarea></p>
  <p><select name="s1" size="1">
    <option>opt1</option>
    <option>opt2</option>
  </select> </p>
</form>
</body>
</html>
0
 
LVL 17

Author Comment

by:Tacobell777
ID: 9864265
Gwyn,

your a superstar!!

Thanks..........
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Expert Comment

by:jaysolomon
ID: 9864279
Gwyn,

are you a superstar

;)
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 9864306
:o), Now I am blushing.
0
 
LVL 17

Author Comment

by:Tacobell777
ID: 9864385
I now have

function fnTrace()
{
      if ( typeof(document.activeElement.name) == 'undefined' )
      {
            alert('You did not click a valid object, or the object\ndoes not have any properties associated with it.\nPlease try again');
            // trace again
            if ( bDecide )
                  fnTrace()
      }
      else if ( document.activeElement.name != '' )
      {
            alert(document.activeElement.name);
      }
}

The //trace again  part will not work, because this whole function relies on an object loosing focus. Is there a way to make it work like above?

PS. I'll open up another question if its to difficult.. Let me know.
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 9864496
try this click the trace button then off the form and then on a form element to test

<html>
<head>
<script language="JavaScript">
function trace()
 { if (document.activeElement.name==undefined)
    {alert(document.activeElement.name+" is in focus please try again")
     document.tform.tbutt.focus()}
   else  
     alert(document.activeElement.name+" is in focus")
}
</script>

<title></title>
</head>

<body>

<form name="tform">
  <p><input type="button" value="trace next" name="tbutt" onblur="trace()"> </p>
</form>

<form name="f1">
  <p><input type="input" size="70" name="t1"> </p>
  <p><input type="button" value="click me" name="b1"></p>
  <p><textarea name="t1" rows="1" cols="20"></textarea></p>
  <p><select name="s1" size="1">
    <option>opt1</option>
    <option>opt2</option>
  </select> </p>
</form>
</body>
</html>
0
 
LVL 17

Author Comment

by:Tacobell777
ID: 9870444
Brilliant.. Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

920 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

13 Experts available now in Live!

Get 1:1 Help Now