MigrantFirmWorker
Programmer
I wish to build a table and assign event callbacks with dynamically generated arguments. In the sample code below I am trying to pass the row and column value associated with the cell that is clicked. What I really need is the values of 'row' and 'col', not the variables themselves.
In the past I have set the ID of the cell to some parseable string containing all the info I needed but I'm assuming there is a more elegant approach.
Any help will be appreciated.
function cellClicked(rr, cc) {
function populateTable() {
Chris
-------------------------------------------------------------
"Don't be deceived. We're all temporary employees.
In the past I have set the ID of the cell to some parseable string containing all the info I needed but I'm assuming there is a more elegant approach.
Any help will be appreciated.
function cellClicked(rr, cc) {
// do something useful.
}function populateTable() {
var myTable = getElementById("initiallyEmptyTable");
for (var row=0; row<5; row++) {
}for (var row=0; row<5; row++) {
var myRow = document.createElement("tr");
for (var col=0; col<6; col++) {
myTable.appendChild(myRow);
}for (var col=0; col<6; col++) {
myCell = document.createElement("td");
myCell.onclick = function(){cellClicked(row, col);};
myRow.appendChild(myCell);
}myCell.onclick = function(){cellClicked(row, col);};
myRow.appendChild(myCell);
myTable.appendChild(myRow);
Chris
-------------------------------------------------------------
"Don't be deceived. We're all temporary employees.