By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,600 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,600 IT Pros & Developers. It's quick & easy.

adding multiple rows to a table at one go.

P: n/a
Amy
Is it possible to do so?

Sep 5 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Amy wrote:
Is it possible to do so?
Do what?

Richard.

Sep 5 '06 #2

P: n/a
Jim
Amy wrote:
Is it possible to do so?
Simple answer, yet.

Really horrible script demonstrating a way to add 2 rows:

<html>

<body>

<script type="text/javascript">

function addRow(id){
var table = document.getElementById(id);
var rowToClone = table.rows[0];
var oRow = rowToClone.cloneNode(true);
var input = oRow.getElementsByTagName('input')[0];
input.name = 'input' + table.rows.length;
input.value = '';
rowToClone.parentNode.appendChild(oRow);
}

function add2Row(id){
var table = document.getElementById(id);
var rowToClone = table.rows[0];
var oRow = rowToClone.cloneNode(true);
var input = oRow.getElementsByTagName('input')[0];
for(var i=0;i<2;i++) {
input.name = 'input' + table.rows.length;
input.value = '';
rowToClone.parentNode.appendChild(oRow);
}
}

</script>

<button onclick="addRow('tableA')">Add row</button><br>
<button onclick="add2Row('tableA')">Add 2 rows</button>
<form action="">
<table id="tableA">
<tr>
<td><input name="input0" onclick="this.value=this.name"></td>
</tr>
</table>
</form>
</body>
</html>
Sep 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.