![]() |
|
,
0 Comments
)
|
| Subject:
Adding more than one row at a time to a table dynamically with dhTML.
Category: Computers > Programming Asked by: roderick_thomas-ga List Price: $2.00 |
Posted:
02 Feb 2003 13:31 PST
Expires: 04 Mar 2003 13:31 PST Question ID: 156431 |
I have some sample javascript code that will display a new row
dynamically to a table. The problem is i need the code to add more
than one row at a time instead of just one.
The code is as follows:
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<script language="javascript">
/*
Function to append row (<TR> object) from template table(Id=Table1)
to Target table (Id = Table)
*/
function AddRow()
{
var vTrgTbl = window.document.getElementById('Table');
var vSrcTbl = window.document.getElementById('Table1');
var vRow = vSrcTbl.lastChild.firstChild.cloneNode(true);
var i;
var noRows = 3;
for (var i = 0; i < noRows; i++)
vTrgTbl.lastChild.appendChild(vRow);
}
</script>
</HEAD>
<BODY>
<!-- Target table in which the row to be appended at the end -->
<p> Click Add button to add rows
<table id="Table">
<tr>
<td> <INPUT type="checkbox" name="ChkBox"> </td>
<td> <INPUT type="Text" name="TxtCnt"> </td>
<td>
<SELECT id=CmbLng name=CmbLng>
<OPTION value=1>One</OPTION>
<OPTION value=2>Two</OPTION>
<OPTION value=3>Three</OPTION>
</SELECT>
</td>
</tr>
</table>
<table>
<tr>
<td> <INPUT type="button" value="ADD" onclick="AddRow()"></td>
</tr>
</table>
<div style="visibility:hidden">
<!-- Template table that contians row to be appended into the first
table -->
<table id="Table1">
<tr>
<td> <INPUT type="checkbox" name="ChkBox"> </td>
<td> <INPUT type="Text" name="TxtCnt"> </td>
<td>
<SELECT id=CmbLng name=CmbLng>
<OPTION value=1>One</OPTION>
<OPTION value=2>Two</OPTION>
<OPTION value=3>Three</OPTION>
</SELECT>
</td>
</tr>
</table>
</div>
<P> </P>
</BODY>
</HTML> |
|
| Subject:
Re: Adding more than one row at a time to a table dynamically with dhTML.
Answered By: bio-ga on 03 Feb 2003 08:50 PST Rated: ![]() |
Hi,
You seem to have all the code you need, only with a small bug... You
just have to re-initialize the variable vRow in each iteration:
So, change the function AddRow() such that:
function AddRow()
{
var vTrgTbl = window.document.getElementById('Table');
var vSrcTbl = window.document.getElementById('Table1');
var i;
var noRows = 3;
for (var i = 0; i < noRows; i++) {
var vRow = vSrcTbl.lastChild.firstChild.cloneNode(true);
vTrgTbl.lastChild.appendChild(vRow);
}
}
Hope this helps
Regards
Bio |
roderick_thomas-ga
rated this answer:
thnx. I figured it out 5 secs after posting here, but I appreciate the help nonetheless. |
|
| There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
| Search Google Answers for |
| Google Home - Answers FAQ - Terms of Service - Privacy Policy |