newbiescooby
Technical User
Hi
I wrote this function to create a series of buttons that relate to different elements of my array an pass the index value j a function. However all the buttons return the same j value.
function CreateButtons()
{
var container = document.getElementById("ButtonContainer");
for(var i=0; i<RowNum-5; i++)
{
var tempButton = null;
var j = i+5;
tempButton = document.createElement("button");
tempButton.Id = "btn" + j
tempButton.value = ContentArray[j][0]+"mm";
tempButton.onclick = function(){alert(j);};
container.appendChild(tempButton);
}
}
Thanks
I wrote this function to create a series of buttons that relate to different elements of my array an pass the index value j a function. However all the buttons return the same j value.
function CreateButtons()
{
var container = document.getElementById("ButtonContainer");
for(var i=0; i<RowNum-5; i++)
{
var tempButton = null;
var j = i+5;
tempButton = document.createElement("button");
tempButton.Id = "btn" + j
tempButton.value = ContentArray[j][0]+"mm";
tempButton.onclick = function(){alert(j);};
container.appendChild(tempButton);
}
}
Thanks