I am stuck at this problem. I have this code (string is of the form: 'var1,var2,var3', and someIdArray is an array containing some id's):
function myFunction1(variable,string)
{
var myArray = string.split(',');
for (i=0;i<myArray.length;i++)
{
for (j=0;j<someIdArray[j].length;j++)
{
document.getElementById(someIdArray[j]).onclick=function() { myFunction2(variable,myArray[i]) };
}
}
}
function myFunction2(variable1,variable2)
{
alert(variable1);
alert(variable2);
}
Now when I click an element with an id in someIdArray, myFunction2 runs, and I get variable1 as I put it in myFunction1, but variable2 is undefined. How can I make sure that the onclick I defined for the element I clicked has fixed variables?