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.