Solved

Capture element name

Posted on 2003-12-02
9
444 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

758 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

20 Experts available now in Live!

Get 1:1 Help Now