Hi
Sorry but to view the code below you'll have to copy it into a temp.html file,
haven't access to a online web page anymore.
The code switches the rows and columns of a table. Its been tried in the
versions below. Note that it works in the latest version of IE before SP2,
whats changed?
By not working I mean that it'll switch the columns/rows twice then lose
some of the information? Can fix it by substituting the commented out lines
for the ones above.
mozilla 1.7.2, works
firefox 0.9.3, works
IE6.0.2800, works
IE6.0.2900, doesn't work
Any ideas
Ta
F
<style>
..theTableClass
{
border: groove;
}
</style>
<table id=theTable class=theTableC lass>
<tr id=realOne>
<td class=Bob sue>Some random text </td>
<td class=Sue>Some random text </td>
<td class=Sue>Some random text </td>
</tr>
</table>
<input type=button value=pressme onclick=SwapCol umnsAndRows('th eTable')>
<script>
function SwapColumnsAndR ows(tableId)
{
var theTable = document.getEle mentById(tableI d)
if(theTable == null) return;
var theTable2 = document.create Element("table" );
var numRows = theTable.rows.l ength;
var numCells = theTable.rows[0].cells.length;
for(var i=0; i<numCells; i++)
{
var newRow = theTable2.inser tRow(-1)
for(var j=0; j<numRows; j++)
{
var cell = theTable.rows[j].cells[i];
//var newCell = theTable2.rows[i].insertCell(-1);
var newCell = newRow.insertCe ll(-1);
SwapCells(cell, newCell);
}
}
while (theTable.rows. length > 0)
{
theTable.delete Row(0);
}
var numRows = theTable2.rows. length;
var numCells = theTable2.rows[0].cells.length;
for(var i=0; i<numRows; i++)
{
var newRow = theTable.insert Row(-1)
for(var j=0; j<numCells; j++)
{
var cell = theTable2.rows[i].cells[j];
//var newCell = theTable.rows[i].insertCell(-1);
var newCell = newRow.insertCe ll(-1);
SwapCells(cell, newCell);
}
}
while (theTable2.rows .length > 0)
{
theTable2.delet eRow(0);
}
}
function SwapCells (cell1, cell2)
{
var dummyCell;
if (document.creat eElement && (dummyCell = document.create Element('td')))
{
cell1.parentNod e.replaceChild( dummyCell, cell1);
cell2.parentNod e.replaceChild( cell1, cell2);
dummyCell.paren tNode.replaceCh ild(cell2, dummyCell);
}
}
</script>
Sorry but to view the code below you'll have to copy it into a temp.html file,
haven't access to a online web page anymore.
The code switches the rows and columns of a table. Its been tried in the
versions below. Note that it works in the latest version of IE before SP2,
whats changed?
By not working I mean that it'll switch the columns/rows twice then lose
some of the information? Can fix it by substituting the commented out lines
for the ones above.
mozilla 1.7.2, works
firefox 0.9.3, works
IE6.0.2800, works
IE6.0.2900, doesn't work
Any ideas
Ta
F
<style>
..theTableClass
{
border: groove;
}
</style>
<table id=theTable class=theTableC lass>
<tr id=realOne>
<td class=Bob sue>Some random text </td>
<td class=Sue>Some random text </td>
<td class=Sue>Some random text </td>
</tr>
</table>
<input type=button value=pressme onclick=SwapCol umnsAndRows('th eTable')>
<script>
function SwapColumnsAndR ows(tableId)
{
var theTable = document.getEle mentById(tableI d)
if(theTable == null) return;
var theTable2 = document.create Element("table" );
var numRows = theTable.rows.l ength;
var numCells = theTable.rows[0].cells.length;
for(var i=0; i<numCells; i++)
{
var newRow = theTable2.inser tRow(-1)
for(var j=0; j<numRows; j++)
{
var cell = theTable.rows[j].cells[i];
//var newCell = theTable2.rows[i].insertCell(-1);
var newCell = newRow.insertCe ll(-1);
SwapCells(cell, newCell);
}
}
while (theTable.rows. length > 0)
{
theTable.delete Row(0);
}
var numRows = theTable2.rows. length;
var numCells = theTable2.rows[0].cells.length;
for(var i=0; i<numRows; i++)
{
var newRow = theTable.insert Row(-1)
for(var j=0; j<numCells; j++)
{
var cell = theTable2.rows[i].cells[j];
//var newCell = theTable.rows[i].insertCell(-1);
var newCell = newRow.insertCe ll(-1);
SwapCells(cell, newCell);
}
}
while (theTable2.rows .length > 0)
{
theTable2.delet eRow(0);
}
}
function SwapCells (cell1, cell2)
{
var dummyCell;
if (document.creat eElement && (dummyCell = document.create Element('td')))
{
cell1.parentNod e.replaceChild( dummyCell, cell1);
cell2.parentNod e.replaceChild( cell1, cell2);
dummyCell.paren tNode.replaceCh ild(cell2, dummyCell);
}
}
</script>
Comment