Vernon R. Tatem

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromVernon R. Tatem
ToMe
SubjectI need help understanding DOM
Date1 March 2006 23:15
Hello,
My name is Vernon, and I need help understanding the following line of code.
I am retired and am trying to teach myself JacaScript. I understand the
basics but am trying to dynamically create a table, insert some data, and
then if the user 'clicks' on a specific cell, I will try and create another
table with different data. The following is the code I am trying to use but
it does not work. I am sure that the answer is simple, but not for me.

    else{
     tmp="<a href=\"javascript:tracker(\'" +player_id +"\','SC')\"
title=\"Click for player\">"+player_name+"</a>";
     }
  ..
            pfCell.innerText = tmp;
            pfRow.appendChild(pfCell);

legend:
         javascript:tracker  - should call my function named tracker.
         player_id              - id to locate the player in the row
         SC                       - What I should do
         player_name        - name of player

When I hover over the player name, 'click for player' appears, but when I
click nothing happens.   I would like to have the name underscored and
change color.

Thanking you in advance for your help,

Vernon
FromMe
ToVernon R. Tatem
SubjectRe: I need help understanding DOM
Date5 March 2006 11:46
Vernon,

>             pfCell.innerText = tmp;

that line is probably the problem. .innerText will put the contents as text
only (and only works in Opera and IE). Use .innerHTML instead.

anything beyond that, I will need to see in context - on the page itself.

I also recommend you try using Opera, and check the JavaScript console for
errors, they are usually helpful for debugging if you have made a mistake
(assuming it is the type of mistake that creates errors):

http://www.opera.com/download/

The JavaScript console can be found in:
tools - advanced - JavaScript console


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromVernon R. Tatem
ToMe
SubjectRe: I need help understanding DOM
Date19 March 2006 14:08
Tarquin,
I must say many thanks for suggesting that I use Opera for my testing.  It
has helped me tremendously in finding subtle bugs in my code.  However, I
still cannot get to my function.  

 Here is a portion of my code:
<!--// 
function tracker(pfRow_id)
{ 
  some code
}
//-->

and here is the call to it: 
First try:  
 tmp = "<a href=\"javascript:tracker(\'" +pfRow_id ")\" title=\"Click "+
 	"for player scorecard\">"+player_name+"</a>";
pfCell.innerHTML = tmp;

This fails with error  message:
Javascript URL thread: "javascript:tracker('tr_1')"
Error:
name:  ReferenceError
message: Statement on line 1:  reference to undefined variable: tracker
backtrace:
Line 1 of unknown script
  tracker("tr_1")

So I tried doing the following:
tmp = "<div " onclick=\"javascript:tracker("+pfRow.id");"+
	"</div>"; title=\"Click for player  scorecard\">"+player_name+"</a>";

which gave me syntax errors.

What I am trying to do is when the user "clicks" on the name control is
passed to the:  functio tracker.

I do hope you can assist me with this as I cannot go any further at this
moment.
 
Once again, thanks very much for your help
FromMe
ToVernon R. Tatem
SubjectRe: I need help understanding DOM
Date22 March 2006 08:07
Vernon,

> This fails with error  message:
> Javascript URL thread: "javascript:tracker('tr_1')"
> Error:
> name:  ReferenceError
> message: Statement on line 1:  reference to undefined variable: tracker

Ok, this means that the tracker function has not been defined. You may have
forgotten to include the script that adds it, or possibly there is an error
in that script.

> So I tried doing the following:
> tmp = "<div " onclick=\"javascript:tracker("+pfRow.id");</div>";
> title=\"Click for player  scorecard\">"+player_name+"</a>";
>
> which gave me syntax errors.

Indeed. You have several quotes in the wrong places. I will try to make
msense of it:

tmp = "<div><a onclick=\"javascript:tracker('"+pfRow.id+"');\" "+
  "title=\"Click for player scorecard\">"+player_name+"</a></div>";
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.