473,703 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DOM to create <TR> & <TD>

Hi there,

I'm trying dynamically generate extra rows in a table. So far this achieves
this task within the tHead segment:

theTable.tHead. appendChild(doc ument.createEle ment('TR'))

....but this only gives me table rows with no table data cells. So I would
like to know if it's possible to create several <TH> within the tHead row
using this method?

I'm new to DOM manipulation so any information or pointers would be greatly
appreciated.

- Thanks.
Jul 20 '05 #1
4 7252
El Diablo wrote:
Hi there,

I'm trying dynamically generate extra rows in a table. So far this achieves
this task within the tHead segment:

theTable.tHead. appendChild(doc ument.createEle ment('TR'))

....but this only gives me table rows with no table data cells. So I would
like to know if it's possible to create several <TH> within the tHead row
using this method?

Can't you just use the same methodology?
Create a TH (or a TD) element & append it to the TR (as many as are
required). Since the TR is already appended to the thead y'r ok.

GL
Fermin DCG
Jul 20 '05 #2


El Diablo wrote:

I'm trying dynamically generate extra rows in a table. So far this achieves
this task within the tHead segment:

theTable.tHead. appendChild(doc ument.createEle ment('TR'))

...but this only gives me table rows with no table data cells. So I would
like to know if it's possible to create several <TH> within the tHead row
using this method?

I'm new to DOM manipulation so any information or pointers would be greatly
appreciated.


Well, once you know that
document.create Element('tagnam e')
creates an element object with that tagname and you know appendChild it
should be clear that you can store an element object reference in a
variable, append child nodes as follows:
var row = document.create Element('tr');
var cell = document.create Element('td');
cell.appendChil d(document.crea teTextNode('Kib ology.'));
row.appendChild (cell);
cell = document.create Element('td');
cell.appendChil d(document.crea teTextNode('Jav aScript'));
row.appendChild (cell);
...
Then when you are done creating table cells use appendChild on a table
or table section to append the row.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3
Exactly what I needed to know. Many thanks.

"Martin Honnen" <ma*******@yaho o.de> wrote in message
news:40******@o laf.komtel.net. ..


El Diablo wrote:

I'm trying dynamically generate extra rows in a table. So far this achieves this task within the tHead segment:

theTable.tHead. appendChild(doc ument.createEle ment('TR'))

...but this only gives me table rows with no table data cells. So I would like to know if it's possible to create several <TH> within the tHead row using this method?

I'm new to DOM manipulation so any information or pointers would be greatly appreciated.


Well, once you know that
document.create Element('tagnam e')
creates an element object with that tagname and you know appendChild it
should be clear that you can store an element object reference in a
variable, append child nodes as follows:
var row = document.create Element('tr');
var cell = document.create Element('td');
cell.appendChil d(document.crea teTextNode('Kib ology.'));
row.appendChild (cell);
cell = document.create Element('td');
cell.appendChil d(document.crea teTextNode('Jav aScript'));
row.appendChild (cell);
...
Then when you are done creating table cells use appendChild on a table
or table section to append the row.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #4
Hi.
I've got an example.
Here's the code:

<html>
<head>
<title>Exampl e</title>
<script language="javas cript">

function Remove(){
var tbody = document.getEle mentById("tbl") .firstChild;
if(tbody.childN odes.length <= 1)
{
alert('There are no regists!');
return;
}

var tr = tbody.lastChild ;

tbody.removeChi ld(tr);
}

function Insere(){
var tbody=document. getElementById( "tbl").firstChi ld;
var newTR = document.create Element("tr");
var newTD1 = document.create Element("td");
var newTD2 = document.create Element("td");
var newText1 = document.create TextNode(docume nt.cart.primNom e.value);
var newText2 = document.create TextNode(docume nt.cart.ultNome .value);

newTD1.appendCh ild(newText1);
newTD2.appendCh ild(newText2);
newTR.appendChi ld(newTD1);
newTR.appendChi ld(newTD2);
tbody.appendChi ld(newTR);
}
</script>
</head>
<body id="bodyTag">
<button onclick="Remove ()" id=button1 name=button1>Re mover</button>
<button onclick="Insere ()" id=button2 name=button2>Ad icionar</button>
<form id="cart" name=cart>
1º Nome: <input type=text id=primNome name="primNome" >
<br>Último nome: <input type=text id=ultNome name="ultNome">
</form>
<table id=tbl bgcolor=#ffffff >
<tr bgcolor=#ccccff >
<th>1º Nome</td>
<th>Último nome</td>
</tr>
</table>
</body>
</html>

There are words in Portuguese sorry but i don't want to change.
This simple form accepts the first and the last name, and then creates a
<tr> with 2 <tr> for show the values.
Hope this helps.
"El Diablo" <ze*****@zen.co .uk> escreveu na mensagem
news:40******** **************@ lovejoy.zen.co. uk...
Hi there,

I'm trying dynamically generate extra rows in a table. So far this achieves this task within the tHead segment:

theTable.tHead. appendChild(doc ument.createEle ment('TR'))

...but this only gives me table rows with no table data cells. So I would
like to know if it's possible to create several <TH> within the tHead row
using this method?

I'm new to DOM manipulation so any information or pointers would be greatly appreciated.

- Thanks.

Jul 20 '05 #5

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

Similar topics

0
689
by: Matt Adams | last post by:
I want to move the following <PRE> defintion to a css file: <TABLE><TR><TD><PRE>sample text</PRE></TD> <TD> not predefined font</TD></TR></TABLE> should be <TABLE><TR><TD class=aaa>sample text</TD> <TD> not predefined font</TD></TR></TABLE>
5
7572
by: Monty | last post by:
..rowbackgrnd { background-color: #E4E4F2; border-bottom: 1px solid Black; border-left: 1px solid #E4E4F2; border-right: 1px solid #E4E4F2; border-top: 1px solid Black } It works for <td> tags but not <tr> tags. I've tried a number of alternatives but I canlt seem to figure out what I'm doing wrong.
2
11230
by: js | last post by:
I have a table rendered with XSLT. The first column has a radio button controls for user to make a selection for a particular row. All the values in the remaining columns are all concated with a &#xA0; (blank). I need to retieve the text in each cell of that row if the radio button on that row is clicked. Each <TD> has a numeric ID so that I can use it with document.getElementById().innerText method. I use Javascript to assign some...
5
5776
by: Gregor Rot | last post by:
Hi, if i have this code: <form><input type=text name="id1"></form> then with javascript i can reference this with this.form.id1, how can i reference something like this: <table> <tr name="id2"> .. ..
2
5769
by: bissatch | last post by:
Hi, I am trying to use JavaScript to write a table column on a web page. The code is as follows: <html> <head> <script> function displaycount() {
3
1704
by: RC | last post by:
I have a very sime html table like <html><head><title>My Table</title> <style> input { margin: 0; padding: 0; border-width: 0; text-indet: 0; text-align: left } </style></head><body> <table border="1" width="100%"> <caption>Table Title</caption> <tr>
28
13197
by: entfred | last post by:
I have the following line of html: &nbsp;&nbsp1234&nbsp;&nbsp;&nbsp;&nbsp;&nbspabc&nbsp;&nbsp;&nbspyow In Internet Explorer 6.0, the columns look ok using the above html: 1234 abcd yow But, in firefox, for same html, getting this:
4
5260
George Lft
by: George Lft | last post by:
I'm new at building table. Mostly PHP programming . Now I can't seem to fix the size of my table row and column. Any idea? <h4>Two rows and three columns:</h4> <table border="1"> <tr> <td>10000000000000</td> <td>200</td> <td>300</td> </tr> <tr>
1
5504
by: test9991014 | last post by:
Hi folks, I've got something like this: <table> <tr> <td>1</td> <td align=center> <input type=text> </td>
7
2789
by: Xiaoyan | last post by:
Hi,everyone: I have a problem now. I can't get the information between the <tr><td> and </td></tr>. for example: I use this regular expression can't get it, I don't know why. $test=~/<tr><td>(.*)<\/td><\/td>(.*)<\/td><\/tr>/ms; <tr><td>station</td> <td>station number/identification, see chart above: <br> B = GoMoos buoy B location<br> S = New Scantum at the southern edge Jefferys Ledge</td></tr>.
0
8667
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
9117
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
9014
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
8961
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7861
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...
0
5922
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();...
0
4429
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2063
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.