473,785 Members | 2,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inserting Tables in IE 6 using W3C DOM techniques.

I had a problem in IE 6 when trying to insert a table using W3C DOM
techniques.

I found a solution and share it. :)

Initially I had......

*************** *******
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-script-type" content="text/javascript" />

<title>insertTa bleInIE</title>

<script type="text/javascript">
/* <![CDATA[ */

function insertTable() {
var table = document.create Element("table" );
table.setAttrib ute("id","table 2");
var tr = document.create Element("tr");
var td = document.create Element("td");
td.appendChild( document.create TextNode("Some stuff in the cell"));
tr.appendChild( td);
table.appendChi ld(tr);
document.getEle mentById('outpu t').appendChild (table);
}

/* ]]> */
</script>
</head>
<body>
<div>
<input type="button" id="btnInsertTa ble" name="btnInsert Table"
onclick="insert Table()" value="Insert Table" />
</div>

<div id="output"></div>
</body>
</html>
*************** *************
This would work in firefox 1.5 but not in IE 6.

The solution.... you have to explicitly insert the tr into a tbody element
and then the tbody into the table. So the function now becomes:

function insertTable() {
var table = document.create Element("table" );
table.setAttrib ute("id","table 2");
var tbody = document.create Element("tbody" ); // explicitly create a
tbody
var tr = document.create Element("tr");
var td = document.create Element("td");
td.appendChild( document.create TextNode("Some stuff in the cell"));
tr.appendChild( td);
tbody.appendChi ld(tr); // note this new line.
table.appendChi ld(tbody); // append tbody rather than tr
document.getEle mentById('outpu t').appendChild (table);
}

Hope this saves some else an hour or two.

Dec 20 '05 #1
11 2085
Ian
Mellow Crow wrote:
I had a problem in IE 6 when trying to insert a table using W3C DOM
techniques.

I found a solution and share it. :)

Nice, looks like IE is doing the correct thing, table rows should be
contained in a tbody.

The HTML-DOM interface insertRow should add this for you if it isn't there.

Ian
Dec 20 '05 #2
"Mellow Crow" <no*****@nowher e.com> wrote in
news:43******** @duster.adelaid e.on.net:
I had a problem in IE 6 when trying to insert a table using W3C DOM
techniques.

I found a solution and share it. :)

Initially I had......

*************** *******
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"
/> <meta http-equiv="content-script-type" content="text/javascript"
/>

<title>insertTa bleInIE</title>

<script type="text/javascript">
/* <![CDATA[ */

function insertTable() {
var table = document.create Element("table" );
table.setAttrib ute("id","table 2");
var tr = document.create Element("tr");
var td = document.create Element("td");
td.appendChild( document.create TextNode("Some stuff in the
cell")); tr.appendChild( td);
table.appendChi ld(tr);
document.getEle mentById('outpu t').appendChild (table);
}

/* ]]> */
</script>
</head>
<body>
<div>
<input type="button" id="btnInsertTa ble" name="btnInsert Table"
onclick="insert Table()" value="Insert Table" />
</div>

<div id="output"></div>
</body>
</html>
*************** *************
This would work in firefox 1.5 but not in IE 6.

The solution.... you have to explicitly insert the tr into a tbody
element and then the tbody into the table. So the function now
becomes:

function insertTable() {
var table = document.create Element("table" );
table.setAttrib ute("id","table 2");
var tbody = document.create Element("tbody" ); // explicitly
create a
tbody
var tr = document.create Element("tr");
var td = document.create Element("td");
td.appendChild( document.create TextNode("Some stuff in the
cell")); tr.appendChild( td);
tbody.appendChi ld(tr); // note this new line.
table.appendChi ld(tbody); // append tbody rather than tr
document.getEle mentById('outpu t').appendChild (table);
}

Hope this saves some else an hour or two.


Since table rows are also part of table headers ('thead') and table
footers ('tfoot'), are you saying that IE refers to create child table row
elements for these nodes?

As long as you're into experiments, then here might be some more
experiments for you:

* See how the browsers do in adding MORE THAN ONE table header or table
footer element to a table node through calling DOM functions. Try more
than one table body while you're at it.

* Write more than one table header, table footer, and table body into a
table using validated HTML, see how the browser parses it by inspecting
the DOM tree thereafter. (Alternatively report the exceptions you find in
attempting certain calls.)

* Compose a validating simple HTML document in which you create a table
WITHOUT any section elements---no THEAD, no TBODY, no TFOOT----and just a
couple of rows each with a couple of cells (can be void of content).
Inspect the DOM hierarchy to see which browsers imposed section elements
(namely TBODY) into the table, and which rendered it just as you wrote it,
and which conformed to all specifications (HTML, ECMA-262::Javascript ,
DOM).
The results are a curiosity.

Dec 20 '05 #3
Patient Guy <Pa*********@no where.to.be.fou nd.com> wrote in
news:Xn******** **********@207. 115.17.102:
"Mellow Crow" <no*****@nowher e.com> wrote in
news:43******** @duster.adelaid e.on.net:
I had a problem in IE 6 when trying to insert a table using W3C DOM
techniques.

I found a solution and share it. :)

Initially I had......

*************** *******
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"
/> <meta http-equiv="content-script-type" content="text/javascript"
/>

<title>insertTa bleInIE</title>

<script type="text/javascript">
/* <![CDATA[ */

function insertTable() {
var table = document.create Element("table" );
table.setAttrib ute("id","table 2");
var tr = document.create Element("tr");
var td = document.create Element("td");
td.appendChild( document.create TextNode("Some stuff in the
cell")); tr.appendChild( td);
table.appendChi ld(tr);
document.getEle mentById('outpu t').appendChild (table);
}

/* ]]> */
</script>
</head>
<body>
<div>
<input type="button" id="btnInsertTa ble" name="btnInsert Table"
onclick="insert Table()" value="Insert Table" />
</div>

<div id="output"></div>
</body>
</html>
*************** *************
This would work in firefox 1.5 but not in IE 6.

The solution.... you have to explicitly insert the tr into a tbody
element and then the tbody into the table. So the function now
becomes:

function insertTable() {
var table = document.create Element("table" );
table.setAttrib ute("id","table 2");
var tbody = document.create Element("tbody" ); // explicitly
create a
tbody
var tr = document.create Element("tr");
var td = document.create Element("td");
td.appendChild( document.create TextNode("Some stuff in the
cell")); tr.appendChild( td);
tbody.appendChi ld(tr); // note this new line.
table.appendChi ld(tbody); // append tbody rather than tr
document.getEle mentById('outpu t').appendChild (table);
}

Hope this saves some else an hour or two.
Since table rows are also part of table headers ('thead') and table
footers ('tfoot'), are you saying that IE refers to create child table
row elements for these nodes?


Proofreading Correction:

"...are you saying that IE refers to create..."

should read

"...are you saying that IE REFUSES to create..."
As long as you're into experiments, then here might be some more
experiments for you:

* See how the browsers do in adding MORE THAN ONE table header or
table footer element to a table node through calling DOM functions.
Try more than one table body while you're at it.

* Write more than one table header, table footer, and table body into
a table using validated HTML, see how the browser parses it by
inspecting the DOM tree thereafter. (Alternatively report the
exceptions you find in attempting certain calls.)

* Compose a validating simple HTML document in which you create a
table WITHOUT any section elements---no THEAD, no TBODY, no
TFOOT----and just a couple of rows each with a couple of cells (can be
void of content). Inspect the DOM hierarchy to see which browsers
imposed section elements (namely TBODY) into the table, and which
rendered it just as you wrote it, and which conformed to all
specifications (HTML, ECMA-262::Javascript , DOM).
The results are a curiosity.


Dec 20 '05 #4
Ian wrote:
Mellow Crow wrote:
I had a problem in IE 6 when trying to insert a table using W3C DOM
techniques.

I found a solution and share it. :)

Nice, looks like IE is doing the correct thing, table rows should be
contained in a tbody.

The HTML-DOM interface insertRow should add this for you if it isn't there.


I've discovered that the big difference is: IE inserts rows at the END
of the table, after the existing rows. Firefox inserts rows at the
BEGINNING of the table, before the existing rows.

If you have a <thead> and a <tbody> defined, then Firefox will insert
rows at the beginning of the <tbody>. Otherwise, it assumes that the
entire table is a <tbody> and inserts at the top.

Not sure which is the "proper" way to do it, but in this case, I'd say
the IE way makes more sense - when I want to add a row to an existing
table, I generally want it at the END.

Dec 20 '05 #5
Tony wrote:
Ian wrote:
The HTML-DOM interface insertRow should add this for you if it isn't
there.


I've discovered that the big difference is: IE inserts rows at the END
of the table, after the existing rows. Firefox inserts rows at the
BEGINNING of the table, before the existing rows.

If you have a <thead> and a <tbody> defined, then Firefox will insert
rows at the beginning of the <tbody>. Otherwise, it assumes that the
entire table is a <tbody> and inserts at the top.

Not sure which is the "proper" way to do it, [...]


That depends on how you call insertRow().

<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-39872903>
PointedEars
Dec 20 '05 #6
VK

Tony wrote:
I've discovered that the big difference is: IE inserts rows at the END
of the table, after the existing rows. Firefox inserts rows at the
BEGINNING of the table, before the existing rows.
That's an implementation bug in some Mozilla browsers and Safari. It
was explained here:
<http://groups.google.c om/group/comp.lang.javas cript/browse_frm/thread/f1d06d29d2fd415 e/0ba38e911abbbcb 2>

As I said it is easy to fix for all browsers by using optional rowIndex
argument:
insertRow(-1)
If you have a <thead> and a <tbody> defined, then Firefox will insert
rows at the beginning of the <tbody>. Otherwise, it assumes that the
entire table is a <tbody> and inserts at the top.

Not sure which is the "proper" way to do it, but in this case, I'd say
the IE way makes more sense - when I want to add a row to an existing
table, I generally want it at the END.


Naturally. This is why it's a rather silly implementation bug.

Also note that IE will create tbody section for you automatically - but
not thead or tfoot. Some browsers will not do event that. The rule is:
if you plan to script your table later, mark up all three sections in
advance:
<table>
<thead></thead>
<tfoot></thead>
<tbody>
....
</tbody>
</table>

Dec 21 '05 #7
VK
<table>
<thead></thead>
<tfoot></foot>
<tbody>
....
</tbody>
</table>

Dec 21 '05 #8
VK
And the 3rd final attempt to make it right :-)

<table>
<thead></thead>
<tfoot></tfoot>
<tbody>
....
</tbody>
</table>

Dec 21 '05 #9
VK wrote:
Tony wrote:
I've discovered that the big difference is: IE inserts rows at the END
of the table, after the existing rows. Firefox inserts rows at the
BEGINNING of the table, before the existing rows.
That's an implementation bug in some Mozilla browsers and Safari.
It was explained here:

<http://groups.google.c om/group/comp.lang.javas cript/browse_frm/thread/f1d06d29d2fd415 e/0ba38e911abbbcb 2>
As I said it is easy to fix for all browsers by using optional rowIndex
argument:
insertRow(-1)


Since the HTMLTableElemen t::insertRow() method of W3C DOM Level 2 HTML
_requires_ that argument, that is, it is _not_ optional, how could
unexpected behavior due to omission of that argument possibly be
considered an "implementa tion bug"?

You are talking nonsense again.
PointedEars
Dec 22 '05 #10

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

Similar topics

0
2426
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish, Swedish or English). There are about a dozen tables with columns that need localization. Doing this in the application level was a no-goer. It would have taken far too much time (there is a *lot* of code and unfortunately most of the...
44
3897
by: Mariusz Jedrzejewski | last post by:
Hi, I'll be very grateful if somebody can explain me why my Opera 7.23 (runing under linux) doesn't show me inner tables. Using below code I can see only "inner table 1". There is no problem with other browsers (I checked it under Konqueror). Thank you in advance for your help. Regards. /Mariusz <HTML>
81
5186
by: sinister | last post by:
I wanted to spiff up my overly spartan homepage, and started using some CSS templates I found on a couple of weblogs. It looks fine in my browser (IE 6.0), but it doesn't print right. I tested the blogs, and one definitely didn't print right. Surveying the web, my impression is that CSS is very unreliable, because even updated browsers fail to implement the standards correctly. So should one just avoid CSS? Or is it OK if used...
3
6920
by: Joachim Klassen | last post by:
Hi all, first apologies if this question looks the same as another one I recently posted - its a different thing but for the same szenario:-). We are having performance problems when inserting/deleting rows from a large table. My scenario: Table (lets call it FACT1) with 1000 million rows distributed on 12
4
12381
by: Tom Dauria | last post by:
What I am trying to do is write a resume into a word document from information in an Access database. I have been using bookmarks and inserting table results into the document and so far it's working but I have run into a problem. The final section of the resume deals with Experience which is subgrouped by Market Segments and then experience. What I want it to look like is
5
2237
by: aniket_sp | last post by:
i am using a data adapter and a dataset for filling and retrieving data into .mdb database. following is the code..... for the form load event Dim dc(0) As DataColumn Try If OleDbConnection1.State = ConnectionState.Closed Then OleDbConnection1.Open() Else
11
4380
by: c676228 | last post by:
Hi everyone, I am just wodering in asp program, if there is anybody writing store procedure for inserting data into database since there are so many parameters need to be passed into store procedure(assume there are many columns in the table). I need to insert data into two separate tables, the relation between these two tables is 1 row of data in table1 could have multiple rows in table2 related to table1, but if the data insertion into...
0
1767
by: gp | last post by:
I am and have been using PDO for about a year now...and have finally gotten around to solving the "DB NULL value" issues I ran into early on... I am looking for suggestions and techniques to deal with inserting DB NULL values into my MySQL 5.x DB Tables....I am running PHP 5.2.x on BSD 6.x with Apache 2.2.x.... As mentioned I am writing all my web apps using the PDO extension to connect and operate on the database. I realized early...
2
3097
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography section: Discography --------------------- DiscID
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10152
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8974
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.