Function uniteTable (tableId, colLength ){
// ColLength -- start with column 1 of the cells to be merged
Var tb = document. getElementById (tableId );
Tb. style. display = '';
Var I = 0;
Var j = 0;
Var rowCount = tb. rows. length; // number of rows
Var colCount = tb. rows [0]. cells. length; // Number of Columns
Var obj1 = null;
Var obj2 = null;
// Name each cell
For (I = 0; I <rowCount; I ++ ){
For (j = 0; j <colCount; j ++ ){
Tb. rows [I]. cells [j]. id = "tb _" + I. toString () + "_" + j. toString ();
}
}
// Merge rows
For (I = 0; I <colCount; I ++ ){
If (I = colLength) break;
Obj1 = document. getElementById ("tb _ 0 _" + I. toString ())
For (j = 1; j <rowCount; j ++ ){
Obj2 = document. getElementById ("tb _" + j. toString () + "_" + I. toString ());
If (obj1.innerText = obj2.innerText ){
Obj1.rowSpan ++;
Obj2.parentNode. removeChild (obj2 );
} Else {
Obj1 = document. getElementById ("tb _" + j. toString () + "_" + I. toString ());
}
}
}
// Merge Columns
For (I = 0; I <rowCount; I ++ ){
ColCount = tb. rows [I]. cells. length;
Obj1 = document. getElementById (tb. rows [I]. cells [0]. id );
For (j = 1; j <colCount; j ++ ){
If (j> = colLength) break;
If (obj1.colSpan> = colLength) break;
Obj2 = document. getElementById (tb. rows [I]. cells [j]. id );
If (obj1.innerText = obj2.innerText ){
Obj1.colSpan ++;
Obj2.parentNode. removeChild (obj2 );
J = j-1;
}
Else {
Obj1 = obj2;
J = j + obj1.rowSpan;
}
}
}
}