473,785 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Uncaught exception when calling rowIndex.

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>

Jul 23 '05 #1
7 2473


me*********@hot mail.com wrote:

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. 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);
}


We need to see where you call the function, exactly what you pass in as
an argument, make sure it is really a row element object.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
me*********@hot mail.com wrote:
[W]hen I call delete row on any new rows that have been created, I
get the following error:
Could you create a minimal example and provide a URL? It's much easier
to diagnose a problem when it can be seen in action.

[snip]
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) + ':'));
I would seriously consider learning to apply the var keyword within
functions. It is not a good idea to dump loads of variables into the
global object.

[snip]
delLink.setAttr ibute('onClick' , "removeField(n_ " + (tbCount+1)
+ "); return false");


Isn't the argument to removeField supposed to be a string? You should
change that second argument to

'removeField("n _' + (tbCount + 1) + '"); return false;'

That said, this isn't a reliable way to create event listeners (though
it will certainly work in Mozilla). If you plan on using this code in
a wider environment, take the traditional approach:

delLink.onclick = function() {
removeField('n_ ' + (tbCount + 1));
return false;
};

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
I don't have a webserver in which I can deploy my code, but I can give
you the full page source if that will help.

When I add a row to a table through JavaScript, is the internal
representation of the table and rows still accessable as if the rows
where there when the page was rendered initially? I noticed that when I
add a row using table.insertRow (table.rows.len gth) and then
alert(table.row s.length), the number is always the same. So, if I had 3
rows rendered initially, the alert would display three. When I append a
couple more rows using the code below, the row count would still be
three. That leads me to believe that A) The rows are appended in some
other structure, or B) I have no clue what I am doing! I am willing to
accept B over A at this point. =-)

As for the parameter to the move method being wrapped in quotes. If I
do that, it actually returns a string, but when I leave the quotes out,
it returns the HTMLTableRowEle ment, which works nice because I should
be able to get the rowIndex from it (but I am not, I am getting this
exception!).

Anyway, thanks for your help and quick replies! Below is the full
source for the page.
Thanks again!
AR.

<html>
<head>
<title></title>

<script type="text/javascript">
var newArray = new Array();
var exArray = new Array();
var delArr = new Array();

var tbCount=<%= @form.inputs.co unt %>;

function addField() {
table = document.getEle mentById('field Table');

row = table.insertRow (table.rows.len gth);
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;
}
alert(rowToDele te.rowIndex);
table = document.getEle mentById('field Table');
table.deleteRow (rowToDelete.ro wIndex);
}
</script>

</head>
<body>
<%= start_form_tag( {:action => "save_field s", :id => @form.id}, "id"
=> "fieldForm" ) %>

<table id="fieldTable" >
<% i = 0
@form.inputs.ea ch do |field|
i = i + 1
%>
<tr id="e_<%= i %>">
<td>
Field <%= i %>:
</td>
<td>
<%= text_field "name", field.id, "value" => field.name %>
</td>
<td>
<%= text_field "descriptio n", field.id, "value" => field.descripti on
%>
</td>
<td>
<a href="#" onClick="remove Field(<%= 'e_' + i.to_s %>); return
false;">Delete</a>
<!-- %= link_to("Delete ", :action => "delete_fie ld", :id => field.id
) % -->
</td>
</tr>
<% end %>
</table>
<input type="submit" value="Save"/>
<%= hidden_field "field_coun t", "count", "value" => @form.inputs.co unt
%>
<%= end_form_tag %>
<a href="#" onClick="addFie ld(); return false;">Add Field</a>

</body>
</html>

Jul 23 '05 #4
me*********@hot mail.com wrote:
I don't have a webserver in which I can deploy my code, but I can
give you the full page source if that will help.
In it's current form, no. Please show the *output* of the server-side
code (preferably with only a minimal set of input data).
I noticed that when I add a row using
table.insertRow (table.rows.len gth)
You can use

table.insertRow (-1);

to append a row.
and then alert(table.row s.length), the number is always the same.
In which browser? Both IE6 and Firefox 1.0 update the row count. I'd
expect Opera to as well.
As for the parameter to the move method being wrapped in quotes. If
I do that, it actually returns a string, but when I leave the
quotes out, it returns the HTMLTableRowEle ment [...]


My apologies. I should have double-checked. However, you shouldn't
rely on that behaviour. Obtaining a reference to an element through
its id attribute value alone is not well supported (and in my opinion,
a horrible feature to implement).

On the subject of sending a reference though, this can easily be
achieved with a slight modification to the code I posted:

function addField() {
/* ... */

var row = table.insertRow (-1);

/* ... */

delLink.onclick = function() {
removeField(row );
return false;
};

/* ... */
}

For that to work the variable, row, *must* be local (as above).

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
Thanks Michael, you have given me some things to think about. Listed
below is the output of the rendered HTML page.

Thanks again!
AR.

<html>
<head>
<title></title>

<script type="text/javascript">
var newArray = new Array();
var exArray = new Array();
var delArr = new Array();

var tbCount=1;

function addField() {
table = document.getEle mentById('field Table');

row = table.insertRow (table.rows.len gth);
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];

swit:h (rowType) {
case 'e':
break;
case 'n':
break;
}
alert(rowToDele te.rowIndex);
table = document.getEle mentById('field Table');
table.deleteRow (rowToDelete.ro wIndex);
}
</script>

</head>
<body>
<form action="/form/save_fields/1" id="fieldForm" method="post">

<table id="fieldTable" >

<tr id="e_1">

<td>
Field 1:
</td>
<td>
<input id="name_1" name="name[1]" size="30" type="text" value="ID"
/>
</td>
<td>
<input id="description _1" name="descripti on[1]" size="30"
type="text" value="Serial Number" />
</td>

<td>
<a href="#" onClick="remove Field(e_1); return false;">Delete</a>
<!-- %= link_to("Delete ", :action => "delete_fie ld", :id => field.id
) % -->
</td>
</tr>

</table>
<input type="submit" value="Save"/>
<input id="field_count _count" name="field_cou nt[count]" type="hidden"
value="1" />
</form>
<a href="#" onClick="addFie ld(); return false;">Add Field</a>

</body>
</html>

Jul 23 '05 #6
OK, I figured out why the table.rows.leng th wasn't updating. If you
look at my code, I first do a

row = table.insertRow (XXXX);

then later in the code, I manually add that row to the table
again....some funky stuff must have been happening behind the scenes.

AR.

Jul 23 '05 #7


me*********@hot mail.com wrote:
function addField() {
table = document.getEle mentById('field Table');
It was already suggested to make sure your function uses local variables
e.g.
var table = ... row = table.insertRow (table.rows.len gth); var row = ...
and so on. That also means you can use
delLink.setAttr ibute('onClick' , "removeField(n_ " + (tbCount+1) + ");
return false");
delLink.onclick = function (evt) {
removeField(row );
return false;
};
here instead of what you have, setAttribute is unfortunately implemented
in different ways in different browsers.

table.appendChi ld(row);
Don't do that if you have called insertRow above to create the row.
Indeed even if you used createElement to create a row don't call
appendChild on the table itself, instead make sure you insert into a tbody.

function removeField(row ToDelete) { table = document.getEle mentById('field Table');
table.deleteRow (rowToDelete.ro wIndex);
You could simply do
rowToDelete.par entNode.removeC hild(rowToDelet e);
for those two lines.

<table id="fieldTable" >

<tr id="e_1">

<td>
Field 1:
</td>
<td>
<input id="name_1" name="name[1]" size="30" type="text" value="ID"
/>
</td>
<td>
<input id="description _1" name="descripti on[1]" size="30"
type="text" value="Serial Number" />
</td>

<td>
<a href="#" onClick="remove Field(e_1);


Don't rely on elements being accessible by variables of the name of the
id attribute, that works in IE and some other browsers (unfortunately
even in Firefox 1.0 in quirks mode) but for cross-browser support you
should use document.getEle mentById e.g.
<a onclick="var row;
if (document.getEl ementById && (row =
document.getEle mentById('e_1') )) {
removeField(row );
}
return false;"

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3291
by: Matt Bostock | last post by:
Hi, When I validate this page: http://www.drfunkenstein.net/using http://jigsaw.w3.org/css-validator/, I get the following results: http://jigsaw.w3.org/css-validator/validator?profile=css2&warning=2&uri=http%3A//www.drfunkenstein.net/ Or briefly: "Uncaught error java.lang.Exception: Import loop detected in
4
3191
by: nrhayyal | last post by:
hi all, i am facing a problem in catching an exception which is uncaught in any of the catch block. not doing so will gives me coredump. I tried by rewriting set_unexpected() and set_terminate() function. But these works fine only for small programs. when i tried with my large applications which links to n num of different libraries, it doesnot work. so please help me to handle uncaught exception on any of the UNIX flavors(it will be...
8
14509
by: scorpion53061 | last post by:
Additional information: Exception from HRESULT: 0x800A03EC. This code produced this error. I am pretty sure I got this to run a while back and I was wondering if you all see anything I am doing wrong.....or do you have a suggestion for a better way.......I do know this method is quite slow. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
3
3473
by: c.prerovsky | last post by:
Hi there, I started messing around with JavaScript OOP a few days ago and still can't get this one to work. There are many things wich keep confusing me, eg. the various ways to define a class or especially methods. Ok, here's the code I'm trying to get to work. I'm trying to create a selection mask with drag handles, which will enable the user to select an area of an image. currently I'm stuck with "el.addEventListener('mousedown',...
2
7201
by: funktacular | last post by:
Hi - I have some javascript that works when I run it from a server, but I need to run it locally. When I try to execute it locally I get the following error: Error: uncaught exception: Permission denied to get property Window.processXML Is there a way to get around this issue? default.htm
9
14156
by: xhunter | last post by:
Hi, I have written my code to load some content through ajax, which works perfectly, then I thought of adding a timeout to retry the action in case it has failed or something. here is the code : var requestTimer = setTimeout(function() { xmlHttp.send(post); }, 10000);
3
2542
by: George2 | last post by:
Hello everyone, Just want to check whether my understanding is correct, Both (1) and (2) only covers Windows C++ platform. 1. If there is uncaught exception, destructor is not ensured to be called for active object;
2
7477
by: josephx | last post by:
Hello, I got some of these errors listed below after executing an HTTP Post MIDlet on CLDC/MIDP platform, "Nokia S40 DP 2.0 SDK 1.1" and "S40 5th Edition SDK Feature Pack 1" and even for S60's SDK.. the application stops. However, it does work only on "Sun Java(TM) Wireless Toolkit 2.5.1 for CLDC" with the same errors displayed, but the application was able to execute successfully. Errors received are: Using Untrusted simulated domain...
5
2240
by: Paul Rubin | last post by:
I think I've asked about this before, but is there a way to set up Python to handle uncaught exceptions with pdb? I know about setting sys.except_hook to something that calls pdb, but this is normally done at the outer level of a program, and by the time that hook gets called, the exception has already unwound the stack to the outermost level. My situation is I run a multi-hour or multi-day computation that eventually crashes due to some...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.