M
meaneyedcat
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)
[nsIDOMHTMLTableRowElement.rowIndex]" 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...specifically rowToDelete.rowIndex 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.count %>;
function addField() {
newArray[tbCount]=document.createElement('INPUT');
table = document.getElementById('fieldTable');
row = document.createElement('tr');
row.id = 'n_' + (tbCount + 1);
fieldCell = document.createElement('td');
fieldCell.appendChild(document.createTextNode('Field ' +
(tbCount + 1) + ':'));
nameCell = document.createElement('td');
nameInput = document.createElement('input');
nameInput.id = 'nname' + (tbCount + 1);
nameInput.name = 'nname[' + (tbCount + 1) + ']';
nameInput.type = 'text';
nameInput.size = '30';
nameCell.appendChild(nameInput);
descCell = document.createElement('td');
descInput = document.createElement('input');
descInput.id = 'newdesc' + (tbCount + 1);
descInput.name = 'newdesc[' + (tbCount + 1) + ']';
descInput.type = 'text';
descInput.size = '30';
descCell.appendChild(descInput);
delCell = document.createElement('td');
delLink = document.createElement('a');
delLink.href = "#";
delLink.setAttribute('onClick', "removeField(n_" + (tbCount+1) +
"); return false");
delLink.appendChild(document.createTextNode('Delete'));
delCell.appendChild(delLink);
table.appendChild(row);
row.appendChild(fieldCell);
row.appendChild(nameCell);
row.appendChild(descCell);
row.appendChild(delCell);
tbCount++;
}
function removeField(rowToDelete) {
array = rowToDelete.id.split('_');
rowType = array[0];
rowId = array[1];
switch (rowType) {
case 'e':
break;
case 'n':
break;
}
table = document.getElementById('fieldTable');
table.deleteRow(rowToDelete.rowIndex);
}
</script>
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)
[nsIDOMHTMLTableRowElement.rowIndex]" 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...specifically rowToDelete.rowIndex 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.count %>;
function addField() {
newArray[tbCount]=document.createElement('INPUT');
table = document.getElementById('fieldTable');
row = document.createElement('tr');
row.id = 'n_' + (tbCount + 1);
fieldCell = document.createElement('td');
fieldCell.appendChild(document.createTextNode('Field ' +
(tbCount + 1) + ':'));
nameCell = document.createElement('td');
nameInput = document.createElement('input');
nameInput.id = 'nname' + (tbCount + 1);
nameInput.name = 'nname[' + (tbCount + 1) + ']';
nameInput.type = 'text';
nameInput.size = '30';
nameCell.appendChild(nameInput);
descCell = document.createElement('td');
descInput = document.createElement('input');
descInput.id = 'newdesc' + (tbCount + 1);
descInput.name = 'newdesc[' + (tbCount + 1) + ']';
descInput.type = 'text';
descInput.size = '30';
descCell.appendChild(descInput);
delCell = document.createElement('td');
delLink = document.createElement('a');
delLink.href = "#";
delLink.setAttribute('onClick', "removeField(n_" + (tbCount+1) +
"); return false");
delLink.appendChild(document.createTextNode('Delete'));
delCell.appendChild(delLink);
table.appendChild(row);
row.appendChild(fieldCell);
row.appendChild(nameCell);
row.appendChild(descCell);
row.appendChild(delCell);
tbCount++;
}
function removeField(rowToDelete) {
array = rowToDelete.id.split('_');
rowType = array[0];
rowId = array[1];
switch (rowType) {
case 'e':
break;
case 'n':
break;
}
table = document.getElementById('fieldTable');
table.deleteRow(rowToDelete.rowIndex);
}
</script>