...

View Full Version : Loading event handler function with variable?



cortic
01-23-2003, 05:01 AM
Ok, I need an onClick put into cells in a table, I also need the function it calls to be given a unique number.. so:
document.getElementById('cell').onclick=function(){fire(4,5)};
if it were only that easy lol, I have something like 30 different cells a few tables and need to give each a unique two numbers, the tables are created dynamically and so the natural progression:

just the td insert part run under two for loop with 'a' that jumps per table and 'b' that jumps per cell ~~

var td = document.createElement('TD');
td.setAttribute('id','this'+a+'_'+b)
tr.appendChild(td);
document.getElementById('this'+a+'_'+b).onclick=function(){fire(a,b)};

of course this doesn't work, the function is an actual function and takes the value of 'a' and 'b' when its triggered (long after the loops are done)

that's my problem, my question? Is there any conceivable way to store these numbers somehow linked with the onClick? I'm at a loss here, I can't see any way round this other than writing out a stupid number of onClick calls - or using normal tables.

Any help or comment would be greatly appreciated, thanks.

cortic
01-23-2003, 04:10 PM
Hit & SCORE lmao.

var td = document.createElement('TD');
td.setAttribute('id',ths'+a+'_'+b)
td.arg1=a;
td.arg2=b;
td.onclick=fire;
tr.appendChild(td);

and I got it from this forum too lol



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum