For an abstract algebra class that I will be teaching,
I'm trying to convert a text-based game that I wrote
in Common Lisp to a graphical game in javascript. (I
know nothing of javascript, but I have three books
from the library that I have been s*l*o*w*l*y going
through.)
Currently I have a large, say, 30x20, table
<table id="GameTable" >
<tr<td>A</td<td>B</td<td>C</td... </tr>
<tr<td>D</td<td>E</td<td>F</td... </tr>
...
</table>
I'm accessing elements via
var game_table = document.getEle mentById('GameT able');
var curr_cell;
function game_node(x,y) {
curr_cell = game_table.rows[x].cells[y];
return(curr_cel l.firstChild);
};
and I'm able to write/read to
game_node(x,y). nodeValue
just fine. But here's where I'm stuck:
I'd like, when the user clicks on, say, cell (3,5),
that a function-call
UpdateGame(3,5)
is invoked. Is there a way I can do this NEITHER
having an "onclick=" NOR an "id=" for each and every
<td>? I seek something like having a single "id=" and
"onclick=" for the entire table, e.g,
<table id="GameTable"
onclick="Update Game(this.rowIn dex, this.colIndex)" >
where -somehow- variables rowIndex and colIndex were
automagically set by the mouse-click.
Ta, Jonathan King Math dept, Univ. of Florida
I'm trying to convert a text-based game that I wrote
in Common Lisp to a graphical game in javascript. (I
know nothing of javascript, but I have three books
from the library that I have been s*l*o*w*l*y going
through.)
Currently I have a large, say, 30x20, table
<table id="GameTable" >
<tr<td>A</td<td>B</td<td>C</td... </tr>
<tr<td>D</td<td>E</td<td>F</td... </tr>
...
</table>
I'm accessing elements via
var game_table = document.getEle mentById('GameT able');
var curr_cell;
function game_node(x,y) {
curr_cell = game_table.rows[x].cells[y];
return(curr_cel l.firstChild);
};
and I'm able to write/read to
game_node(x,y). nodeValue
just fine. But here's where I'm stuck:
I'd like, when the user clicks on, say, cell (3,5),
that a function-call
UpdateGame(3,5)
is invoked. Is there a way I can do this NEITHER
having an "onclick=" NOR an "id=" for each and every
<td>? I seek something like having a single "id=" and
"onclick=" for the entire table, e.g,
<table id="GameTable"
onclick="Update Game(this.rowIn dex, this.colIndex)" >
where -somehow- variables rowIndex and colIndex were
automagically set by the mouse-click.
Ta, Jonathan King Math dept, Univ. of Florida
Comment