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

Creating table with DOM is invisible with IE ?

Hi,

I'm trying just to display a table on a webpage using DOM elements
created dynamically.

I really don't understand why IE doesn't display the document
successfully...
If I make a copy/paste of the output, I can see the data.
Mozilla displays successfully a table... Check this little code :

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Test</title>
</head>
<body onload="">
<table>

</table>
<p></p>
</body>

<script type="text/javascript">
var pItem = document.getElementsByTagName("p").item(0);
pItem.appendChild( document.createTextNode("TEST") );

function onLoaded(infoOn) {
var table = document.getElementsByTagName("table").item(0);

for(val in infoOn) {
currentRow = document.createElement("tr");
currentCell = document.createElement("td");
currentText = document.createTextNode(val);
currentCell.appendChild( currentText );
currentRow.appendChild(currentCell);
table.appendChild(currentRow);
}
table.style.visibility = "visible";
table.setAttribute("border", "1");

}
onLoaded(document.getElementsByTagName("table"));
</script>
</html>
On IE, this code "displays" only "TEST" but try Copy/paste and the data
will be pasted... so what is the problem ?

Thank you very much.

Mar 26 '06 #1
4 2378
GRenard said the following on 3/26/2006 1:31 AM:
Hi,

I'm trying just to display a table on a webpage using DOM elements
created dynamically.

I really don't understand why IE doesn't display the document
successfully...
<URL:
http://msdn.microsoft.com/library/de...dude100499.asp


IE wants a TBODY. Whether you hard code it or create it dynamically.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 26 '06 #2
Thank you very much, it works perfectly ! It just weird that I can use
tr or td hardcoded but not dynamically directly...

Thank you again !

Mar 26 '06 #3
GRenard wrote:
Hi,

I'm trying just to display a table on a webpage using DOM elements
created dynamically.

I really don't understand why IE doesn't display the document
successfully...
If I make a copy/paste of the output, I can see the data.
Mozilla displays successfully a table... Check this little code :

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Test</title>
</head>
<body onload="">
<table>

</table>
<p></p>
</body>

<script type="text/javascript">
var pItem = document.getElementsByTagName("p").item(0);
pItem.appendChild( document.createTextNode("TEST") );

function onLoaded(infoOn) {
var table = document.getElementsByTagName("table").item(0);

for(val in infoOn) {
currentRow = document.createElement("tr");
As Randy said, IE requires that the tr element be added to a tbody, not
directly to the table (and use var to keep variables local).

Rather than creating a tbody element, you can also use insertRow:

var currentRow = table.insertRow(-1);

Passing a row index of -1 will insert the row as the last row of the table.

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-39872903>

currentCell = document.createElement("td");
You can also use:

var currentCell = currentRow.insertCell(-1);

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-68927016>

currentText = document.createTextNode(val);
currentCell.appendChild( currentText );
currentRow.appendChild(currentCell);
If insertCell is used, the cell is already added to the row so this line
isn't required.

table.appendChild(currentRow);
If insertRow is used, the row is already added to the table so this line
isn't required either.

}
table.style.visibility = "visible";
table.setAttribute("border", "1");

}
onLoaded(document.getElementsByTagName("table"));
</script>
</html>
On IE, this code "displays" only "TEST" but try Copy/paste and the data
will be pasted... so what is the problem ?

Thank you very much.

--
Rob
Mar 26 '06 #4


GRenard wrote:
It just weird that I can use
tr or td hardcoded but not dynamically directly...


That is how HTML as an SGML application works, if your document markup
has e.g.
<table>
<tr>
<td>
then the SGML parser adds a tbody element in the DOM tree to be a child
of the table element and the parent of the tr element.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 26 '06 #5

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

Similar topics

5
by: Ivo | last post by:
Consider a table with a number of rows, each containing a short text (label) on the left and an input control on the right. Some inputs are of type text and others of type checkbox. I would like...
1
by: andrewkooi | last post by:
Greetings, I have 16 links for my horizontal menu navigation as you can see in my website www.singakad.com and at present, I am using a table and javascript for this menu. Is it possible for...
1
by: Susan Geller | last post by:
I have a table server control (System.Web.UI.WebControls.Table) on my form that has three columns. Sometimes I need the second column to be invisible, sometimes the third. How can I set a column...
4
by: Net Developer | last post by:
I need to create a wizard like interface where a person picks an item on the first page, then goes to the next page, makes a choice there, .... Ideally it will need to be user object because of...
8
by: TORQUE | last post by:
Hi, I am having some trouble with recording a field on a form into my Table after formatting it to calculate several fields on the form. If i just put the amount in the field and have it linked...
11
by: CodeLeon | last post by:
Hi. I would like to create a keylogger, are there any good tutorials? Also, more importantly, how do i hide this process from the task manager? NO, i am not a virus writer, so PLEASE no messages...
4
by: TS | last post by:
I am losing my colgroup html element of a table that i toggle back and forth of being visible=true/false. is there any workaround since the rendered html doesn't contain it even though it has not...
5
by: my.shabby.sheep | last post by:
Hi, I want to do the following. I want to make a table column invisible to the screen, but I still want to be able to get the innertext that would have been stored in the cell for certain...
2
by: chris | last post by:
I've created an ASP table which is dynamically populated and it has a hidden column at the end. The cell is marked as invisible but when I try and obtain the cell value in client side script...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.