PDA

View Full Version : Dynamic Row Appends to Table


gblair
10-24-2002, 03:14 AM
Could anyone suggest to me a way that I could dynamically (on Button click) append/delete a predefined row to a table that would work in both IE and Netscape? I've had success in IE but Netscape is being a pain. The idea here is that this table would contain database search criteria and the user, upon clicking a button, would be able to append as many search criteria as they wished. What I've done to this point is have a table with one predefined row created (initially hidden) and as the user adds criteria, this row is replicated as another row in the table (sort of a cookie-cutter type approach). I will include the code I've been using to this point in IE:

The function I use to append a row:

function addRow(table) {
var blankRow=table.rows["blankRow"];
var newRow=table.insertRow();
for (i=0; i<blankRow.cols; i++) {
newRow.insertCell().innerHTML = blankRow.cells[i].innerHTML }

The table definition that contains the pre-defined (hidden) row that is to be appended on every button click:

<table border=0 id="myTable">
<tr>
<td> </td>
<td> <strong>Column</strong> </td>
<td> <strong>Operator</strong> </td>
<td> <strong>Search Term</strong> </td>
</tr>
<tr id="blankRow" cols=4 style="display:none">
<td id="myColumn">
<select name="myAndOr">
etc....
</tr></table>

I call the function like this:

addRow(document.myTable);

Netscape seems to be giving me the following errors with this code:
<1> On calling the addRow function, Netscape returns an error saying it doesn't recognize the "myTable" object even though I've predefined the id in the table definition. Am I calling it incorrectly?
<2> I seem to be having problems in Netscape with the "cols=4" in the row definition (highlighted).

All this to say that I would be appreciative in anyone could suggest some way I could fix this code *or* could suggest another way to do this row-addition that would work in both IE and Netscape. I am *totally* flexible at this point! LOL

Regards,
Geoff

Garadon
10-24-2002, 07:10 AM
shouldn't it be 'name="myTable"' and not 'id="myTable"'


and try colspan

Roy Sinclair
10-24-2002, 03:01 PM
No it's not name="myTable". The problem is that the reference to the table is using an IE only shortcut.

addRow(document.myTable);

should be

addRow(document.getElementById("myTable"));