Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    New Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •