When I call addField(), my table appears to be populated correctly
with a new row in the table with all the required fields. However,
when I call delete row on any new rows that have been created, I get
the following error:
Error: uncaught exception: [Exception... "Component returned failure
code: 0x80004002 (NS_NOINTERFACE )
[nsIDOMHTMLTable RowElement.rowI ndex]" nsresult: "0x80004002
(NS_NOINTERFACE )" location: "JS frame ::
http://localhost:3000/form/edit_fields/1 :: removeField :: line 65"
data: no]
The error appears to happen when the last line of removeField() gets
called...specif ically rowToDelete.row Index throws the exception.
I should mention that I am running this code on Firefox 1.0, however,
when I run it on IE6, it doesn't work either, but I don't know what
the error is (I just don't know how to get a trace of the JavaScript
errors).
thanks for your help!
Aaron.
<script type="text/javascript">
var newArray = new Array();
var exArray = new Array();
var delArr = new Array();
var tbCount=<%= @form.inputs.co unt %>;
function addField() {
newArray[tbCount]=document.creat eElement('INPUT ');
table = document.getEle mentById('field Table');
row = document.create Element('tr');
row.id = 'n_' + (tbCount + 1);
fieldCell = document.create Element('td');
fieldCell.appen dChild(document .createTextNode ('Field ' +
(tbCount + 1) + ':'));
nameCell = document.create Element('td');
nameInput = document.create Element('input' );
nameInput.id = 'nname' + (tbCount + 1);
nameInput.name = 'nname[' + (tbCount + 1) + ']';
nameInput.type = 'text';
nameInput.size = '30';
nameCell.append Child(nameInput );
descCell = document.create Element('td');
descInput = document.create Element('input' );
descInput.id = 'newdesc' + (tbCount + 1);
descInput.name = 'newdesc[' + (tbCount + 1) + ']';
descInput.type = 'text';
descInput.size = '30';
descCell.append Child(descInput );
delCell = document.create Element('td');
delLink = document.create Element('a');
delLink.href = "#";
delLink.setAttr ibute('onClick' , "removeField(n_ " + (tbCount+1) +
"); return false");
delLink.appendC hild(document.c reateTextNode(' Delete'));
delCell.appendC hild(delLink);
table.appendChi ld(row);
row.appendChild (fieldCell);
row.appendChild (nameCell);
row.appendChild (descCell);
row.appendChild (delCell);
tbCount++;
}
function removeField(row ToDelete) {
array = rowToDelete.id. split('_');
rowType = array[0];
rowId = array[1];
switch (rowType) {
case 'e':
break;
case 'n':
break;
}
table = document.getEle mentById('field Table');
table.deleteRow (rowToDelete.ro wIndex);
}
</script>