Hello all,
I am working on a function that renames each table row's elements, as well as reassigning the function calls dynamically. I ran into a problem where I am trying to assign the new functions. Pardon me if this sounds confusing, here is the snippet of code.
[CODE=javascript]
var i;
for(i=1; i<=numRows; i++) {
tbl.rows[i].id = "row" + i; //Rename each row
tbl.rows[i].cells[0].firstChild.id = "serial" + i; //Rename each serial element
tbl.rows[i].cells[1].childNodes[0].id = "ncCode" + i; //Rename each ncCode element
tbl.rows[i].cells[1].childNodes[1].id = "configCode " + i; //Rename each configure button element
tbl.rows[i].cells[1].childNodes[1].onclick = function() {
configureCode(i ); // <== here is the problem
}
}
[/CODE]
I have marked where the problem is, basically the configureCode function expects a number, and I want to be able to pass in a parameter of i which is the loop counter, that way as I rename an element, I reassign the parameters for the function to that new element. How would I be able to pass in the value of i into the configureCode function? Thanks for your help.
Edit: I have also tried different variations to try to get the function to accept the value of i with no avail.
[CODE=javascript]
tbl.rows[i].cells[1].childNodes[1].onclick = configureCode(i );
[/CODE]
and
[CODE=javascript]
tbl.rows[i].cells[1].childNodes[1].onclick = function(i) {
configureCode(i );
}
[/CODE]
I am working on a function that renames each table row's elements, as well as reassigning the function calls dynamically. I ran into a problem where I am trying to assign the new functions. Pardon me if this sounds confusing, here is the snippet of code.
[CODE=javascript]
var i;
for(i=1; i<=numRows; i++) {
tbl.rows[i].id = "row" + i; //Rename each row
tbl.rows[i].cells[0].firstChild.id = "serial" + i; //Rename each serial element
tbl.rows[i].cells[1].childNodes[0].id = "ncCode" + i; //Rename each ncCode element
tbl.rows[i].cells[1].childNodes[1].id = "configCode " + i; //Rename each configure button element
tbl.rows[i].cells[1].childNodes[1].onclick = function() {
configureCode(i ); // <== here is the problem
}
}
[/CODE]
I have marked where the problem is, basically the configureCode function expects a number, and I want to be able to pass in a parameter of i which is the loop counter, that way as I rename an element, I reassign the parameters for the function to that new element. How would I be able to pass in the value of i into the configureCode function? Thanks for your help.
Edit: I have also tried different variations to try to get the function to accept the value of i with no avail.
[CODE=javascript]
tbl.rows[i].cells[1].childNodes[1].onclick = configureCode(i );
[/CODE]
and
[CODE=javascript]
tbl.rows[i].cells[1].childNodes[1].onclick = function(i) {
configureCode(i );
}
[/CODE]
Comment