?
Solved

Capture element name

Posted on 2003-12-02
9
Medium Priority
?
470 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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

840 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