473,396 Members | 2,011 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.

Dynamic Table Creation Not working

Hi,

The following code for dynamic table creation is not working.
Can anyone please help me.
The dynamically created rows and columns are not getting populated.

CODE:
=========

[HTML]<html>
<head>
<title>Sample code - Traversing an HTML Table with JavaScript and DOM Interfaces</title>
<script>
[/HTML]
Expand|Select|Wrap|Line Numbers
  1.     function startLoad() {
  2.         var tbl = document.getElementById("tbl");
  3.       var tblBody = document.getElementById("tblBody");
  4.     var newTblBody = document.createElement("newTblBody");
  5.     newTblBody.id = "tblBody";
  6.  
  7.         for (var j = 0; j < 2; j++) {
  8.             // creates a table row
  9.             var row = document.createElement("tr");
  10.  
  11.             for (var i = 0; i < 2; i++) {
  12.                 // Create a <td> element and a text node, make the text
  13.                 // node the contents of the <td>, and put the <td> at
  14.                 // the end of the table row
  15.                 var cell = document.createElement("td");
  16.                 var cellText = document.createTextNode("cell is row " + j + ", column " + i);
  17.                 cell.appendChild(cellText);
  18.                 row.appendChild(cell);
  19.             }
  20.  
  21.             // add the row to the end of the table body
  22.             newTblBody.appendChild(row);
  23.         }
  24.  
  25.         // put the <tbody> in the <table>
  26.         tbl.replaceChild(newTblBody, tblBody);
  27.         // sets the border attribute of tbl to 2;
  28.         tbl.setAttribute("border", "2");
  29.     }
[HTML]</script>
</head>

<body onload="startLoad()">
<table id="tbl" border="1" width="100%" cellspacing="0">
<thead>
<tr>
<td class="header">Col 1</td>
<td class="header">Col 2</td>
</tr>
</thead>

<tbody id="tblBody">
</tbody>
</table>
</body>

</html>[/HTML]

===========================
Sep 26 '07 #1
3 2062
dmjpro
2,476 2GB
Welcome to TSDN!
Use Code Tags, read Posting Guidelines before Post.

Expand|Select|Wrap|Line Numbers
  1. //var newTblBody = document.createElement("newTblBody");
  2. //it is wrong, the right one is given below
  3. var newTblBody = document.createElement("TBODY");
  4.  
Kind regards,
Dmjpro.
Sep 26 '07 #2
Hi Dmjpro,

Thanks a lot for your help. It works. Great.
Sorry that I haven't included the code tag.

Thanks and Regards,
Arunan

Welcome to TSDN!
Use Code Tags, read Posting Guidelines before Post.

Expand|Select|Wrap|Line Numbers
  1. //var newTblBody = document.createElement("newTblBody");
  2. //it is wrong, the right one is given below
  3. var newTblBody = document.createElement("TBODY");
  4.  
Kind regards,
Dmjpro.
Sep 26 '07 #3
acoder
16,027 Expert Mod 8TB
Removed "please help" from the thread title.
Sep 26 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Krzys! | last post by:
I'd like to create a table dynamicly. List of column in this table should be taken from select: "select distinct fiel from table " How to do it ? tnx in advance for help K.
3
by: Eddie de Bear | last post by:
Hi, A project I am working on has a requirement for dynamic menus. For the most part this works really well. The menus I'm creating a based on files and directories, so naturally the menu...
2
by: Dave Williamson | last post by:
When a ASPX page is created with dynamic controls based on what the user is doing the programmer must recreate the dynamic controls again on PostBack in the Page_Load so that it's events are wired...
3
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which...
1
by: russ | last post by:
Hi all, Here's a problem I'm having with a dynamic table. Following the guidelines here (http://www.codeproject.com/aspnet/dynamiccontrols.asp), which make perfect sense. The problem is that...
13
by: rn5a | last post by:
In a shopping cart app, suppose a user has placed 5 orders, I want to show him 5 LinkButtons (one for each order) so that when he clicks the first LinkButton, he would be shown the details of his...
4
by: vamshiv | last post by:
hi...im working on asp.net with VB i have created a database which hav fields id,name,image path in web form i hav written code for creation of image buttons dynamically i hav connected the form...
3
polymorphic
by: polymorphic | last post by:
I have succeeded in embedding PDF files in a dynamic iframe. The problem is that I need the PDF to cache. If the PDF remains the same from page load to page load then the pdf is somehow cached with...
3
by: tokcy | last post by:
hi everyone, i am creating dynamic row in a table using javascript its working fine and now i want to create more than 1 table using javascript which is dynamic its also working fine but when i am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
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,...
0
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...

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.