Synchronized Table Events

Discussion Thread.

Demo

This demo shows two uses of xTableSync: (1) A syncronized mouseover/out effect. (2) Click on a TD in either table and it's contents get assigned to the corresponding TD in the other table.

t1r1c0t1r1c1t1r1c2t1r1c3t1r1c4t1r1c5t1r1c6t1r1c7t1r1c8t1r1c9
t1r2c0t1r2c1t1r2c2t1r2c3t1r2c4t1r2c5t1r2c6t1r2c7t1r2c8t1r2c9
t1r3c0t1r3c1t1r3c2t1r3c3t1r3c4t1r3c5t1r3c6t1r3c7t1r3c8t1r3c9
t1r4c0t1r4c1t1r4c2t1r4c3t1r4c4t1r4c5t1r4c6t1r4c7t1r4c8t1r4c9
t1r5c0t1r5c1t1r5c2t1r5c3t1r5c4t1r5c5t1r5c6t1r5c7t1r5c8t1r5c9
t1r6c0t1r6c1t1r6c2t1r6c3t1r6c4t1r6c5t1r6c6t1r6c7t1r6c8t1r6c9
T2R1C0T2R1C1T2R1C2T2R1C3T2R1C4T2R1C5T2R1C6T2R1C7T2R1C8T2R1C9
T2R2C0T2R2C1T2R2C2T2R2C3T2R2C4T2R2C5T2R2C6T2R2C7T2R2C8T2R2C9
T2R3C0T2R3C1T2R3C2T2R3C3T2R3C4T2R3C5T2R3C6T2R3C7T2R3C8T2R3C9
T2R4C0T2R4C1T2R4C2T2R4C3T2R4C4T2R4C5T2R4C6T2R4C7T2R4C8T2R4C9
T2R5C0T2R5C1T2R5C2T2R5C3T2R5C4T2R5C5T2R5C6T2R5C7T2R5C8T2R5C9
T2R6C0T2R6C1T2R6C2T2R6C3T2R6C4T2R6C5T2R6C6T2R6C7T2R6C8T2R6C9

Usage

/*
xTableSync(sT1Id, sT2Id, sEvent, fn)
sT1Id, sT2Id - table id strings.
sEvent - event type string ('click', 'mouseover', etc).
fn - callback function, called when sEvent occurs on a TD in either table.
     fn(td1, td2)
     td1 - the TD which received the event.
     td2 - the corresponding TD in the other table.
*/

xAddEventListener(window, 'load',
  function() {
    xTableSync('table1', 'table2', 'click', tblClick);
    xTableSync('table1', 'table2', 'mouseover', tblMOver);
    xTableSync('table1', 'table2', 'mouseout', tblMOut);
  }, false
);
function tblClick(td1, td2)
{
  td2.innerHTML = td1.innerHTML;
}
function tblMOver(td1, td2)
{
  td1.className = 'tdOver';
  td2.className = 'tdOver';
}
function tblMOut(td1, td2)
{
  td1.className = 'tdOut';
  td2.className = 'tdOut';
}

Related Demos

More Table Toys.