I have been trying to create a dynamic id for a number of images in a
table so that I can identify which image was clicked on later. ie I
need to set a variable to the id of each image, that is generated by a
loop. The info is read from an XML file in another function and each
section of info is stored as a separate object; Each object is
pertaining to one row in the table.
function createTable ()
{
var output, dynamId;
output="<table id=thisTableId><TR><TH>.....< \/ TH><\/ TR>" ;
//length is a number given earlier, containing the
//number of rows that need to be in the table
//object is an array of objects, each object containing
//information i want shown in the table
for (var count = 0; count < length; count++)
{
dynamID="img"+ count;
output+= "<TR><TD><img src='images\\littlex.gif' id=dynamID
onClick=work(id)><\ /img><\/ TD>";
//showing the data in the columns
output+= '<TD class=content>' + object[count].name + '<\/ TD>' +
'<TD class=content align=center>' +
object[count].region +
'<\/ TD><\/ TR>';
}
output += "<\/ table>";
}
function work (num)
{
alert (num);
}
My goal is to have an image clickable in each row of the table in the
left column, except for the header. The image should provide some
indication of what row it is located in. This information will be used
to change the information in another cell of the same row, but i know
how to do that part. The various combinations I have tried, generally
return [null], [object] or the last id no matter which image is
pressed. If needed, it is possible to put more variables into the
object.
Any suggestions would be helpful. Thanks in advance