473,396 Members | 1,749 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,396 software developers and data experts.

DOM build table IE trouble ..........

Hi.
I'm not able to understand
why this simple snippet doesn't
work with IE.
It works fine with FF and Opera 9.

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
function buildTable()
{
var content = document.getElementById('content');
var mTable = document.createElement('table');
mTable.setAttribute('cellspacing','0');
mTable.setAttribute('cellpadding','0');
var tr = document.createElement('tr');
var td = document.createElement('td');
td.appendChild(document.createTextNode('pippo'));
tr.appendChild(td);
mTable.appendChild(tr);
alert(mTable);
content.appendChild(mTable);
}
window.onload = function()
{
buildTable();
}

</script>

</head>
<body>
<div id="content"></div>
</body>
</html>
Bye :(

Jan 14 '07 #1
10 1641
whisher wrote:
var mTable = document.createElement('table');

mTable.cellSpacing = '0';
mTable.cellPadding = '0';

var tbody = document.createElement('tbody');
var tr = document.createElement('tr');
var td = document.createElement('td');
td.appendChild(document.createTextNode('pippo'));
tr.appendChild(td);
tbody.appendChild(tr);

mTable.appendChild(tbody);
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 14 '07 #2
Daz

whisher wrote:
Hi.
I'm not able to understand
why this simple snippet doesn't
work with IE.
It works fine with FF and Opera 9.

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
function buildTable()
{
var content = document.getElementById('content');
var mTable = document.createElement('table');
mTable.setAttribute('cellspacing','0');
mTable.setAttribute('cellpadding','0');
var tr = document.createElement('tr');
var td = document.createElement('td');
td.appendChild(document.createTextNode('pippo'));
tr.appendChild(td);
mTable.appendChild(tr);
alert(mTable);
content.appendChild(mTable);
}
window.onload = function()
{
buildTable();
}

</script>

</head>
<body>
<div id="content"></div>
</body>
</html>
Bye :(
I believe you are missing a <tbodyelement. I am not sure if IE will
automatically create it for you, so you'd be better off creating it
manually, and then appending the TRs to that, like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
function buildTable()
{
var content = document.getElementById('content');
var mTable = document.createElement('table');
mTable.setAttribute('cellspacing','0');
mTable.setAttribute('cellpadding','0');
var tbody = document.createElement('tbody');
var tr = document.createElement('tr');
var td = document.createElement('td');
td.appendChild(document.createTextNode('pippo'));
tr.appendChild(td);
tbody.appendChild(tr);
mTable.appendChild(tbody);
alert(mTable);
content.appendChild(mTable);
}
window.onload = function()
{
buildTable();
}

</script>

</head>
<body>
<div id="content"></div>
</body>
</html>

I can't confirm whether or not it works in IE, but I see no reason why
it shouldn't, as the code as it was worked fine with Firefox, but then
again, Firefox is smarter, and more forgiving of errors.

Hope that helps.

All the best.

Daz.

Jan 14 '07 #3

Daz wrote:
whisher wrote:
Hi.
I'm not able to understand
why this simple snippet doesn't
work with IE.
It works fine with FF and Opera 9.

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
function buildTable()
{
var content = document.getElementById('content');
var mTable = document.createElement('table');
mTable.setAttribute('cellspacing','0');
mTable.setAttribute('cellpadding','0');
var tr = document.createElement('tr');
var td = document.createElement('td');
td.appendChild(document.createTextNode('pippo'));
tr.appendChild(td);
mTable.appendChild(tr);
alert(mTable);
content.appendChild(mTable);
}
window.onload = function()
{
buildTable();
}

</script>

</head>
<body>
<div id="content"></div>
</body>
</html>
Bye :(

I believe you are missing a <tbodyelement. I am not sure if IE will
automatically create it for you, so you'd be better off creating it
manually, and then appending the TRs to that, like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
function buildTable()
{
var content = document.getElementById('content');
var mTable = document.createElement('table');
mTable.setAttribute('cellspacing','0');
mTable.setAttribute('cellpadding','0');
var tbody = document.createElement('tbody');
var tr = document.createElement('tr');
var td = document.createElement('td');
td.appendChild(document.createTextNode('pippo'));
tr.appendChild(td);
tbody.appendChild(tr);
mTable.appendChild(tbody);
alert(mTable);
content.appendChild(mTable);
}
window.onload = function()
{
buildTable();
}

</script>

</head>
<body>
<div id="content"></div>
</body>
</html>

I can't confirm whether or not it works in IE, but I see no reason why
it shouldn't, as the code as it was worked fine with Firefox, but then
again, Firefox is smarter, and more forgiving of errors.

Hope that helps.

All the best.

Daz.
No, with IE doesn't work.

I've fixed the problem with:
function buildTable()
{
var content = document.getElementById('content');
var mTable = document.createElement('table');
mTable.setAttribute('cellspacing','0');
mTable.setAttribute('cellpadding','0');
var mTBody = document.createElement('tbody');
var tr = document.createElement('tr');
var td = document.createElement('td');
td.appendChild(document.createTextNode('pippo'));
tr.appendChild(td);
mTBody.appendChild(tr);
mTable.appendChild(mTBody);
content.appendChild(mTable);
}
Bye.

Jan 14 '07 #4

whisher wrote:
Daz wrote:
whisher wrote:
Hi.
I'm not able to understand
why this simple snippet doesn't
work with IE.
It works fine with FF and Opera 9.
>
Code:
>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
function buildTable()
{
var content = document.getElementById('content');
var mTable = document.createElement('table');
mTable.setAttribute('cellspacing','0');
mTable.setAttribute('cellpadding','0');
var tr = document.createElement('tr');
var td = document.createElement('td');
td.appendChild(document.createTextNode('pippo'));
tr.appendChild(td);
mTable.appendChild(tr);
alert(mTable);
content.appendChild(mTable);
}
window.onload = function()
{
buildTable();
}
>
</script>
>
</head>
<body>
<div id="content"></div>
</body>
</html>
>
>
Bye :(
I believe you are missing a <tbodyelement. I am not sure if IE will
automatically create it for you, so you'd be better off creating it
manually, and then appending the TRs to that, like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
function buildTable()
{
var content = document.getElementById('content');
var mTable = document.createElement('table');
mTable.setAttribute('cellspacing','0');
mTable.setAttribute('cellpadding','0');
var tbody = document.createElement('tbody');
var tr = document.createElement('tr');
var td = document.createElement('td');
td.appendChild(document.createTextNode('pippo'));
tr.appendChild(td);
tbody.appendChild(tr);
mTable.appendChild(tbody);
alert(mTable);
content.appendChild(mTable);
}
window.onload = function()
{
buildTable();
}

</script>

</head>
<body>
<div id="content"></div>
</body>
</html>

I can't confirm whether or not it works in IE, but I see no reason why
it shouldn't, as the code as it was worked fine with Firefox, but then
again, Firefox is smarter, and more forgiving of errors.

Hope that helps.

All the best.

Daz.

No, with IE doesn't work.

I've fixed the problem with:
function buildTable()
{
var content = document.getElementById('content');
var mTable = document.createElement('table');
mTable.setAttribute('cellspacing','0');
mTable.setAttribute('cellpadding','0');
var mTBody = document.createElement('tbody');
var tr = document.createElement('tr');
var td = document.createElement('td');
td.appendChild(document.createTextNode('pippo'));
tr.appendChild(td);
mTBody.appendChild(tr);
mTable.appendChild(mTBody);
content.appendChild(mTable);
}
Bye.
Thanks a lot buddies.

Bye.

Jan 14 '07 #5
Daz said the following on 1/14/2007 1:49 PM:

<snip>
I can't confirm whether or not it works in IE, but I see no reason why
it shouldn't, as the code as it was worked fine with Firefox, but then
again, Firefox is smarter, and more forgiving of errors.
Then why does FF get this one dead wrong and IE gets it right? The
reason the original failed is IE won't allow you to append TR to the
TABLE, it requires you to append it to the TBODY - which is in
accordance with specs. FF on the other hand will assume you want a TBODY
and create it for you.

And, FF is "more forgiving of errors"? I guess you have never scripted
IE then.....
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 14 '07 #6

whisher wrote:
Hi.
I'm not able to understand
why this simple snippet doesn't
work with IE.
It works fine with FF and Opera 9.
The others have given you the reason and a solution, but for
simplicity, try insertRow and insertCell. They are convenience methods
designed specifically for building tables. It saves you having to
create and append a tbody, and also saves the append step for rows and
cells.

function buildTable()
{
var content = document.getElementById('content');
var mTable = document.createElement('table');
mTable.setAttribute('cellspacing','0');
mTable.setAttribute('cellpadding','0');
var tr = mTable.insertRow(-1);
var td = tr.insertCell(-1);
td.appendChild(document.createTextNode('pippo'));
content.appendChild(mTable);
}
window.onload = function()
{
buildTable();
}
<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-68927016 >
<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-39872903 >
--
Rob

Jan 14 '07 #7
Daz

Randy Webb wrote:
Daz said the following on 1/14/2007 1:49 PM:

<snip>
I can't confirm whether or not it works in IE, but I see no reason why
it shouldn't, as the code as it was worked fine with Firefox, but then
again, Firefox is smarter, and more forgiving of errors.

Then why does FF get this one dead wrong and IE gets it right? The
reason the original failed is IE won't allow you to append TR to the
TABLE, it requires you to append it to the TBODY - which is in
accordance with specs. FF on the other hand will assume you want a TBODY
and create it for you.
Did you not notice the corrections I'd made to the original script?
>
And, FF is "more forgiving of errors"? I guess you have never scripted
IE then.....
Appending the TR to a TABLE and not a TBODY, I believe is an error. One
that Firefox figures out and fixes, and IE turns it's nose up at. I am
not arguing about specs, but simply stating that Firefox is more
forgiving of errors, which you just confirmed in your first
paragraph... Sorry Randy, but you are getting defnsive over nothing.

Jan 14 '07 #8
Daz

RobG wrote:
whisher wrote:
Hi.
I'm not able to understand
why this simple snippet doesn't
work with IE.
It works fine with FF and Opera 9.

The others have given you the reason and a solution, but for
simplicity, try insertRow and insertCell. They are convenience methods
designed specifically for building tables. It saves you having to
create and append a tbody, and also saves the append step for rows and
cells.

function buildTable()
{
var content = document.getElementById('content');
var mTable = document.createElement('table');
mTable.setAttribute('cellspacing','0');
mTable.setAttribute('cellpadding','0');

var tr = mTable.insertRow(-1);
var td = tr.insertCell(-1);
td.appendChild(document.createTextNode('pippo'));
content.appendChild(mTable);
}
window.onload = function()
{
buildTable();
}

<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-68927016 >
<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-39872903 >
--
Rob
Thanks for that Rob. I for one, was totally unaware of those methods.

Jan 14 '07 #9
Daz said the following on 1/14/2007 6:31 PM:
Randy Webb wrote:
>Daz said the following on 1/14/2007 1:49 PM:
<snip>
>And, FF is "more forgiving of errors"? I guess you have never scripted
IE then.....
Appending the TR to a TABLE and not a TBODY, I believe is an error. One
that Firefox figures out and fixes, and IE turns it's nose up at. I am
not arguing about specs, but simply stating that Firefox is more
forgiving of errors, which you just confirmed in your first
paragraph...
That is just it though, FF is *not* more forgiving, it adheres to the
standards a lot more than IE does but in this instance IE got it right.
It is very rare that IE gets it spec right but FF gets it wrong. And to
say that FF is more forgiving of errors is simply wrong.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 15 '07 #10
Daz

Randy Webb wrote:
Daz said the following on 1/14/2007 6:31 PM:
Randy Webb wrote:
Daz said the following on 1/14/2007 1:49 PM:

<snip>
And, FF is "more forgiving of errors"? I guess you have never scripted
IE then.....
Appending the TR to a TABLE and not a TBODY, I believe is an error. One
that Firefox figures out and fixes, and IE turns it's nose up at. I am
not arguing about specs, but simply stating that Firefox is more
forgiving of errors, which you just confirmed in your first
paragraph...

That is just it though, FF is *not* more forgiving, it adheres to the
standards a lot more than IE does but in this instance IE got it right.
It is very rare that IE gets it spec right but FF gets it wrong. And to
say that FF is more forgiving of errors is simply wrong.
I agree with most of what you say there, but I can't see where Firefox
got it wrong. Perhaps one of us has misread the original post? From
what I could see. Firefox rendered the page correctly with the error,
and IE didn't, but I assume that now, both render the page correctly.

Best wishes.

Daz.
>
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 15 '07 #11

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

Similar topics

10
by: Sims | last post by:
Hi I have a table with something like ID PARENT 0 | -1 1 | -1 2 | 1 3 | 1
10
by: Hung Jung Lu | last post by:
Hi, Does anyone know whether there is any generic GUI-based build system around? (Python-based would be great. Also, for now I am only looking for Windows OS.) By "build system" I mean something...
4
by: Jon Anunson | last post by:
Hi - Ok, i know this isn't ideal, but i'm trying to get a quick job done and having a little trouble, so i've reverted to table layout hoping that would help... here's the problem: to solve some...
10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
8
by: Pavel A. | last post by:
Can anybody shed some light... Confused here :(( Isn't VS.2005 supposed to use the new build system, that can be invoked separately from the IDE? If yes, why it creates vcproj files? Are these...
1
by: ferraro.joseph | last post by:
Hi, I'm querying Salesforce.com via their AJAX toolkit and outputting query results into a table. Currently, their toolkit does not possess the ability to do table joins via their structured...
13
by: 7stud | last post by:
test1.py: -------------------- import shelve s = shelve.open("/Users/me/2testing/dir1/aaa.txt") s = "red" s.close() --------output:------ $ python test1.py
7
by: John Nagle | last post by:
Back in March, I posted this: That was for M2Crypto 0.17. It's still broken in M2Crypto 0.18. And there's no RPM or Windows binary. Nobody actually uses this stuff, do they?
5
dlite922
by: dlite922 | last post by:
Hey guys, I've built applications and I've always wanted my own version and build number that's more like bigger applications. Requirements: 1. The version should be manual (besides...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.