aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes this.title returning undefined Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "this.title returning undefined" Watch "this.title returning undefined" New topic
Author

this.title returning undefined

Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
Hi there,

When I click one of the cells of a table that I have on an HTML page, my javascript function is called.

One of the function's tasks is to assign the contents of the title attribute of whatever element was clicked to call the function, (in this case a table cell), to a variable.

I am using:



Whenever I test to see what has been assigned to the variable, I get 'undefined'. Does anyone know what I might be doing wrong?

Many thanks

Joe


OCPJP 85%
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
We are going to need to see more code than that.

If I had to guess, sounds like your scoping is off.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Does the clicked element have a title attribute?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
Hi Eric,

Thanks for your reply. In order to isolate the problem, I made a separate html page and javascript script, I still get the same response. Here is my HTML:



And here is my javascript:



Regards

Joe
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
do this instead



and



Eric
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Indeed.

Carefully read this: http://www.quirksmode.org/js/this.html
Joe Lemmer
Ranch Hand

Joined: Oct 24, 2008
Posts: 171
Hi Eric,

I implemented what you wrote and it's working great.

Thanks very much for your time, again. I appreciate it.

Regards

Joe
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

This is one of the reasons that assigning click handlers in the HTML markup can trip you up. You might want to look into the concept of Unobtrusive JavaScript.
 
wood burning stoves
 
subject: this.title returning undefined