The simplest way to see why some variations of directly assigning a string containing html fragment cannot set up the passing of "object" itself is this.
[1]>cell.innerHTML = '<a href="#" onclick="fillNewCol(obj,1)">Add More +</a>';
Here obj is within a string. It set up the anchor onclick with passing something called obj to the handler. But obj there has nothing to do with the obj in the function test(obj).
[2] A variation of passing successfully obj.tablename is this: the variation is trying to pass the obj itself.
[tt]cell.innerHTML = '<a href="#" onclick="fillNewCol('+obj+',1)">Add More +</a>';
} //wrong[/tt]
In this format, obj is recognized as the obj in the function test(obj) passed in as an argument. But, the right-hand-side is a string concatination. Any object at that position will be converted to string. How? The object will inherit the .toString() method from its superclass to do the conversion. Hence it is equivalent at its place to be scripted like:
[tt] ... + obj.toString() + ...[/tt]
But the obj.toString() actually is becoming
[tt] ... + [object Object] + ...[/tt]
Hence, any reference to obj itself is lost.
Directly assign the <a href=... onclick=...>...</a> to cell.innerHTML will be successful if the arguments to the onclick handler be a string (such as "mainTable" the name of the global variable - quite non-generic way to do thing, or obj.tablename, here testTag, etc...), but the syntax would not allow passing "object" directly for the above reason.
[3] As an aside, after you successfully set up an anchor inside the div, the onclick event will bubble: even though you probably won't notice it. The anchor is every time redrawn which is probably not what you intend to do. Hence, to make it conceptually neat, you have to eliminate the onclick handler of the div itself. Hence, the setup should start with eliminate the div's onclick handler. The easiest and more graphic way is to do it like this.
[tt]
function makeTestTag(obj)
{
[blue]document.getElementById("testTag").onclick=function(){};[/blue]
//continue the rest...
}
[/tt]