473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SP2 breaks IE

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=theTableClass>
<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=SwapColumnsAndRows('theTable')>

<script>

function SwapColumnsAndRows(tableId)
{
var theTable = document.getElementById(tableId)
if(theTable == null) return;

var theTable2 = document.createElement("table");

var numRows = theTable.rows.length;
var numCells = theTable.rows[0].cells.length;

for(var i=0; i<numCells; i++)
{
var newRow = theTable2.insertRow(-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.insertCell(-1);
SwapCells(cell, newCell);
}
}

while (theTable.rows.length > 0)
{
theTable.deleteRow(0);
}

var numRows = theTable2.rows.length;
var numCells = theTable2.rows[0].cells.length;

for(var i=0; i<numRows; i++)
{
var newRow = theTable.insertRow(-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.insertCell(-1);
SwapCells(cell, newCell);
}
}

while (theTable2.rows.length > 0)
{
theTable2.deleteRow(0);
}
}

function SwapCells (cell1, cell2)
{
var dummyCell;
if (document.createElement && (dummyCell = document.createElement('td')))
{
cell1.parentNode.replaceChild(dummyCell, cell1);
cell2.parentNode.replaceChild(cell1, cell2);
dummyCell.parentNode.replaceChild(cell2, dummyCell);
}
}
</script>
Jul 23 '05 #1
1 1257
fo******@yahoo.co.uk wrote:
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


Here is a little simpler version that works in all the browsers listed above:

<style type="text/css">
..theTableClass {
border: groove;
}
</style>
<table id=theTable class=theTableClass>
<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=SwapColumnsAndRows('theTable')>
<script type="text/javascript">
function SwapColumnsAndRows(tableId) {

var theTable = document.getElementById(tableId)
if (!theTable) {
return;
}

var theTable2 = theTable.cloneNode(false);

var numRows = theTable.rows.length;
var numCells = theTable.rows[0].cells.length;

for(var i = 0; i < numCells; i++) {
var newRow = theTable2.insertRow(-1);
for(var j = 0; j < numRows; j++) {
newRow.appendChild(theTable.rows[j].cells[i].cloneNode(true));
}
}

while (theTable.firstChild) {
theTable.removeChild(theTable.firstChild);
}

for (var i = 0; i < theTable2.childNodes.length; i++) {
if (theTable2.childNodes[i].nodeName == 'TBODY') {
theTable.appendChild(theTable2.childNodes[i]);
break;
}
}
}
</script>

- I do a shallow clone [cloneNode(false)] of the original table (initially I had a
solution that involved theTable.parentNode.replaceChild(theTable2, theTable); but it
did not work in Opera 7.54 - you could probably get away with
document.createElement('table'); now)
- I create a new row for each existing row, then do a deep clone [cloneNode(true)]
of each cell and append it to the new row
- I then remove all children from the original table (note all _children_, not all
rows, doing it this way removes the TBODY)
- I then go through the new table, locate the TBODY and append it to original table
(I suppose I should cloneNode() it, but I don't see the need) - it is necessary to
go looking for the TBODY and not just assume it's firstChild because of the
differences between IE and Gecko-based browsers

Using my code should be much faster than swapping each cell into a new table and
swapping them back. Tested and working in:

IE 6.0.2800 and 6.0.2900
Firefox 0.9.3
Mozilla 1.7.2
Opera 7.54

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bill | last post by:
I am downloading data from a website that displays it in a table $fp = fopen("a website page", 'r'); The following accesses the stream one <td> element at a time $myData = fgets($fp); Then I...
1
by: ChrisC | last post by:
Im having trouble removing line breaks from my c# string. Actually, im having trouble getting .Trim() to work properly, as it seems to count a string that has nowt but a break of some sort as not...
4
by: intl04 | last post by:
I have a memo field that is included in some Access reports I created. Is there some way for the memo field to display nicely formatted text, with line breaks between paragraphs? Or is it necessary...
2
by: Mike | last post by:
I need my textbox to work more smoothly with respect to line breaks. When I have data pulled from the database into a textbox there are hard line breaks at the end of each line (by definition how...
10
by: Evie | last post by:
I understand that when a switch statement is used without breaks, the code continues executing even after a matching case is found. Why, though, are subsequent cases not evaluated? I wrote a...
5
by: joelbyrd | last post by:
Didn't know exactly where to post this, but: How do I get line breaks in a textarea? I'm pulling text from a database, and this text definately has line breaks in it, because I replaced all the...
2
by: caspardh | last post by:
i was trying to code a morse code decipherer which workd fine except that the .txt file that i was converting had linebreaks built in, i cant get python to ignore the line breaks and i cant find any...
8
by: Harris Kosmidis | last post by:
It seems I cannot understand CSS, well. I have donw the following page: http://www.pennias.gr/home.php It's in greek but the context is of no importance. I used a big table to put in my page...
28
by: Kent Feiler | last post by:
1. Here's some html from a W3C recommendations page. <P>aaaaaaaaa<DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</DIV> 2.Although I didn't think it would make any difference, I tried it with the...
0
by: bblue | last post by:
hi, I need help in implementing page breaks in XML files? any suggestion on how can this be done? do you recommend using processing instructions or add a new elements would make more sense? can the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.