Solved

Capture element name

Posted on 2003-12-02
9
449 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 17

Author Comment

by:Tacobell777
ID: 9864265
Gwyn,

your a superstar!!

Thanks..........
0
 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

803 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