?
Solved

Capture element name

Posted on 2003-12-02
9
Medium Priority
?
458 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

770 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