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

Unable to create a table in IE using Javascript.

I don't know the problem with IE6. I have tried three methods, and
they all failed. I eliminated the use of mootools' framework in method
3. MooTools is not the problem. Because the table is created but is
not showing up. I have checked that with IE developper toolbar.

1st method

for(var i = 0; i < thelines.length; i++) {
var newrow = new Element('tr');
for(var j = 0; j < (posArray.length - 1); j++){
var newcol = new Element('td').appendText(result[i][j]);
newcol.injectInside(newrow);
}
newrow.injectInside($('result'));
}

2nd method

for(var i = 0; i < thelines.length; i++ )
{
var newrow = new Element('tr');
for(var j = 0; j < (posArray.length - 1); j++){
var newcol = new Element('td');
var txt = document.createTextNode(result[i][j]);
newcol.appendChild(txt);
newrow.appendChild(newcol);
}
$('result').appendChild(newrow);
}

3rd method

var oTable = document.createElement('table');
var oRow, oCell;
oTable.id = 'result';
for(var i = 0; i < thelines.length; i++ )
{
oRow = document.createElement('tr');
for(var j = 0; j < (posArray.length - 1); j++)
{
oCell = document.createElement('td');
oCell.innerText = result[i][j];
oCell.textContent = result[i][j];
oRow.appendChild(oCell);
}
oTable.appendChild(oRow);
}
oTableContainer = document.getElementById('tablecontainer');
oTableContainer.appendChild(oTable);

May 30 '07 #1
4 5706
no*************@gmail.com wrote :
I don't know the problem with IE6. I have tried three methods, and
they all failed. I eliminated the use of mootools' framework in method
3. MooTools is not the problem. Because the table is created but is
not showing up. I have checked that with IE developper toolbar.
First problem: you have posted code and you have not posted an URL where
we can examine all of the page code. Do not post code; post an URL.
>
1st method

for(var i = 0; i < thelines.length; i++)

How do you create, how have you created the "thelines"? We can not read
that.

{
var newrow = new Element('tr');
What's the Element object? We can not see that.

I disagree and do not recommend creating your own functions when DOM 1
and DOM 2 functions have been already defined, created for such
purposes: why not use createElement() when it has been defined already
and when it should work in all DOM compliant browsers?
for(var j = 0; j < (posArray.length - 1); j++){
var newcol = new Element('td').appendText(result[i][j]);
newcol.injectInside(newrow);
Where is the injectInside function? We can not examine that.

Same comment here too. Why not use the DOM standard appendChild()
function which has been defined, standardized for all DOM compliant
browsers?
}
newrow.injectInside($('result'));
}

2nd method

for(var i = 0; i < thelines.length; i++ )
{
var newrow = new Element('tr');
for(var j = 0; j < (posArray.length - 1); j++){
var newcol = new Element('td');
var txt = document.createTextNode(result[i][j]);
newcol.appendChild(txt);
newrow.appendChild(newcol);
}
$('result').appendChild(newrow);
}

3rd method

var oTable = document.createElement('table');
var oTbody = document.createElement("tbody");
If I recall correctly, MSIE 6+ requires the creation of a tbody (or
table section like thead or tfoot) to append table rows.
var oRow, oCell;
oTable.id = 'result';
for(var i = 0; i < thelines.length; i++ )
{
oRow = document.createElement('tr');
for(var j = 0; j < (posArray.length - 1); j++)
Please verify that you need to substract 1 to the posArray.length. We
can't do this ... without looking to the whole code. An url ...
{
oCell = document.createElement('td');
oCell.innerText = result[i][j];
oCell.textContent = result[i][j];
Right here, the code is not precise.

Try instead:

oCell.appendChild(document.createTextNode(result[i][j]));
oRow.appendChild(oCell);
}
oTable.appendChild(oRow);
Instead,

oTbody.appendChild(oRow);
}
Now, when the external for loop (for rows) is done, append the tbody to
the table:

oTable.appendChild(oTbody);
oTableContainer = document.getElementById('tablecontainer');
oTableContainer.appendChild(oTable);
Since you are going, it seems, to be refering to oTableContainer only
once, then you can merge the 2 above instructions into a single one with:

document.getElementById("tablecontainer").appendCh ild(oTable);

If the above suggestions do not work, then post an url and we'll look at
the whole code.

Gérard
--
Using Web Standards in your Web Pages (Updated Apr. 2007)
http://developer.mozilla.org/en/docs...your_Web_Pages
May 30 '07 #2
Gérard Talbot wrote :
>3rd method

var oTable = document.createElement('table');

var oTbody = document.createElement("tbody");
If I recall correctly, MSIE 6+ requires the creation of a tbody (or
table section like thead or tfoot) to append table rows.
"If DOM Core methods document.createElement and element.appendChild are
used to create rows and cells, IE requires that they are appended to a
tbody element, whereas other browsers will allow appending to a table
element (the rows will be added to the last tbody element)."
http://developer.mozilla.org/en/docs...Examples#Notes

Gérard
--
Using Web Standards in your Web Pages (Updated Apr. 2007)
http://developer.mozilla.org/en/docs...your_Web_Pages
May 30 '07 #3
Thanks Gerard. You are right.
"If DOM Core methods document.createElement and element.appendChild are
used to create rows and cells, IE requires that they are appended to a
tbody element, whereas other browsers will allow appending to a table
element (the rows will be added to the last tbody

May 30 '07 #4
In comp.lang.javascript message <13*************@corp.supernews.com>,
Tue, 29 May 2007 21:35:23, Gérard Talbot <ne***********@gtalbot.org>
posted:
>
First problem: you have posted code and you have not posted an URL
where we can examine all of the page code. Do not post code; post an
URL.
Dial-up users with off-line newsreaders won't like that at all. Others
may prefer not to go to strange URLs on anonymous advice.

Consensus is that problems should be reduced to the minimum code that
shows the problem (that often solves it) and posted here by
copy'n'paste. A URL in addition can be good, but not a URL instead.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
May 31 '07 #5

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

Similar topics

10
by: Peter Kirk | last post by:
Hi there can someone please help me with creating dynamic content in a table? For example, see the below javascript and html - why is a new row not created in the table when I click the button?...
10
by: soup_or_power | last post by:
The pop up window has several checkboxes. I'm unable to access the checkboxes using the handle from window.open. Any way to do this? var display; function showSugg(but_id, sugg1, sugg2, sugg3,...
5
by: Prashant Mahajan | last post by:
I was trying to display a small table on the click event of the button but my browser just displayes plain text (I tried on Firefox and IE both) here is the code : <HTML> <HEAD> <TITLE>...
2
by: Oliver Stratmann | last post by:
Hello All! I've got a problem with our DB2/NT 8.1.0 Database. The following SELECT on a big Table (2,5 Million rows) finishes with the Error "Unable to allocate new pages in table space...
6
by: Vikram | last post by:
I have added some input elements on a page using javascript at client side. when i submit the page, i am unable to access the values of input elements created using request.form. Are elements...
5
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public...
3
by: bhanubalaji | last post by:
hi, I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA.. can any one help regarding this.. What's the wrong with my code? I am...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
3
by: ashishc | last post by:
Hi All, I have written a AutoSuggest in jsp and am using javascript to call the strut page which calls the database and returns me the xml back. On the html page i have a text box where i enter...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.