Hello everyone,
I need help with my javascript code. I'm trying to create a dynamic table with onclick event like this but onclick event seems to do nothing:
var srcTable = this.iContext.getElementById("tbody");
var tmpRow = null;
var tmpCell = null;
var i;
for(i=0; i<5; i++)
{
tmpRow = srcTable.insertRow();
tmpRow.onclick = function() { doSomething(this);};
tmpCell = tmpRow.insertCell(tmpRow);
tmpCell.innerText = "Author";
tmpCell = null;
tmpCell = tmpRow.insertCell(tmpRow);
tmpCell.innerText = i;
tmpCell = null;
tmpRow = null;
}
I found a few examples like this:
tmpRow.onclick = function() { alert(this.rowIndex);};
but I need use selected data, maybe call a defined function. I already tried lines bellow but nothing works, because doSomething is not function of tmpRow object.
Can somebody help?
tmpRow.onclick = function() { doSomething(this);};
or
tmpRow.onclick = doSomething(this);
or
tmpRow.onclick = "doSomething(this)";