Trying to put the value of a variable into a function parameter
Hello I have a JSON array data.cells that I need to iterate through to get the values out of and put the values into an onclick event listener.
Right now the variable name data.cells[i].letter is being based through the buildString function for each cell in my board, instead of the value of the variable. Same goes for the x and y variables.
for(var i = 0; i < data.cells.length; i++) {
var x = i % 4 + 1;
var y = 0;
if(i < 4) {
y = 1;
}
else if(i < 8) {
y = 2;
}
else if(i < 12) {
y = 3;
}
else {
y = 4;
}
document.getElementById('t' + i).addEventListener('click',function(data){
buildString(this, data.cells[i].letter, x, y);}, false);
document.getElementById('t' + i).setTextValue(data.cells[i].letter);
}
adaykin
Junior Poster in Training
73 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0
I have no idea what you're trying to do, you're already are passing those variables to the function.
buildString(this, data.cells[i].letter, x, y);
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
So when the buildString function gets called instead of some value for data.cells[i].letter like 'A' the string data.cells[i].letter is being passed to the function. I want to get what the value of data.cells[i].letter is.
adaykin
Junior Poster in Training
73 posts since Feb 2007
Reputation Points: 10
Solved Threads: 0