Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-23-2003, 05:01 AM   PM User | #1
cortic
New Coder

 
Join Date: Aug 2002
Location: UK
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
cortic is an unknown quantity at this point
Loading event handler function with variable?

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.
__________________
corrie track
cortic is offline   Reply With Quote
Old 01-23-2003, 04:10 PM   PM User | #2
cortic
New Coder

 
Join Date: Aug 2002
Location: UK
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
cortic is an unknown quantity at this point
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
__________________
corrie track
cortic is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:29 AM.


Advertisement
Log in to turn off these ads.