473,804 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Table rows collection help

This works in Firefox, but not in IE.

for (var i in appraisertable. rows) {
var row = appraisertable. rows[i];
alert(row.id);
}

IE displays "undefined" and gives the error "id is null or not an
object." Like I said before, Firefox works great. What's my problem
here?

Jun 19 '06 #1
2 5065
Trevor wrote:
This works in Firefox, but not in IE.

for (var i in appraisertable. rows) {
var row = appraisertable. rows[i];
alert(row.id);
}

IE displays "undefined" and gives the error "id is null or not an
object." Like I said before, Firefox works great. What's my problem
here?


Guessing that appraisertable is a table or a tableSection element, then
appraisertable. rows should return a collection. A for..in statement
will iterate over the enumerable properties, if you look at what is
returned by your code, Firefox goes through the indexes first, then the
other properties (length, item, namedItem). IE returns the length
first, so in the first iteration, 'row' is set to the value of the
length property which is a number. Number objects don't have an id
property (unless you've given them one) so it returns undefined.
Firefox does too, but after returning the indexes. Try the following:

<table id="tableA">
<tr id="one"><td>on e</td></tr>
<tr id="two"><td>tw o</td></tr>
<tr id="three"><td> three</td></tr>
</table>

<script type="text/javascript">
function blah(){
var r = document.getEle mentById('table A').rows;
for (i in r){
alert( 'Property: ' + i + '\n'
+ 'Type: ' + (typeof i) + '\n'
+ 'Value: ' + r[i]);
}
}
blah();
</script>

In any case, there seems no point in using for..in - the usual reason
is for sparse arrays, but that should never happen with a rows
collection (they are 'live' and self-adjusting). Use:

var row, rows = appraisertable. rows;
for (var i=0, len=rows.length ; i<len; i++) {
row = rows[i];
if (row.id) alert(row.id);
}

--
Rob

Jun 20 '06 #2
Thank you so much! That's precisely what I needed to know.

RobG wrote:
Trevor wrote:
This works in Firefox, but not in IE.

for (var i in appraisertable. rows) {
var row = appraisertable. rows[i];
alert(row.id);
}

IE displays "undefined" and gives the error "id is null or not an
object." Like I said before, Firefox works great. What's my problem
here?


Guessing that appraisertable is a table or a tableSection element, then
appraisertable. rows should return a collection. A for..in statement
will iterate over the enumerable properties, if you look at what is
returned by your code, Firefox goes through the indexes first, then the
other properties (length, item, namedItem). IE returns the length
first, so in the first iteration, 'row' is set to the value of the
length property which is a number. Number objects don't have an id
property (unless you've given them one) so it returns undefined.
Firefox does too, but after returning the indexes. Try the following:

<table id="tableA">
<tr id="one"><td>on e</td></tr>
<tr id="two"><td>tw o</td></tr>
<tr id="three"><td> three</td></tr>
</table>

<script type="text/javascript">
function blah(){
var r = document.getEle mentById('table A').rows;
for (i in r){
alert( 'Property: ' + i + '\n'
+ 'Type: ' + (typeof i) + '\n'
+ 'Value: ' + r[i]);
}
}
blah();
</script>

In any case, there seems no point in using for..in - the usual reason
is for sparse arrays, but that should never happen with a rows
collection (they are 'live' and self-adjusting). Use:

var row, rows = appraisertable. rows;
for (var i=0, len=rows.length ; i<len; i++) {
row = rows[i];
if (row.id) alert(row.id);
}

--
Rob


Jun 20 '06 #3

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

Similar topics

6
7104
by: David D. | last post by:
I want to be able to access cells within an HTML table, via computed row number and column number. I was considering using oTableID.children and oTR.children arrays. My question is what browsers and browser versions support this? If the children constructs are not fairly universally supported, then what is a better approach to doing this?
4
65906
by: Cris Teta | last post by:
Hi to all, im just newbie in javascript and html dom. I just want to know how will i get the total number of rows in a certain html table? Please help, it will be very much appreciated. Thanks in advance. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
2
23954
by: Joe | last post by:
Hi All, I am new to using the Access DB and I need some help if someone is able to give it to me. What I want to do is get the names of the columns of certain tables. Not the data in the table but the table column names. I've seen other posts that suggest using the SQL command DESCRIBE but I can't get it to work for some reason. Other posts have code samples but they're written in VB which I am not familiar with. I
8
1828
by: John Smith Jr. | last post by:
I am looking for some way to persist a table web control so when page_load event comes up, i can display the table as it was. I tried using ViewState with the rows collection but that didn't work to well as I got an error trying to put rows collection in the viewstate. My problem is this: I load a table with rows and controls, then wire events, this is after clearing the rows of the table initially in this function.
6
4994
by: Ward Germonpré | last post by:
Hi, I have a reference to a dom table. How can I retrieve the number of columns in that table ? The stop value below doesn't work, nor did my experimenting with tbodies and childNodes.. .... var thistable = document.getElementById('resultaattbl'); for (var j=0, stop = thistable.tbody.rows.length; j<stop; j++) {
4
3748
by: jamescostello | last post by:
The code below is part of a script that is imported by a webpage. I am trying to modify a table on that webpage using this code. I can't modify the actual webpage itself. I would like to simply delete the last row from the table. After doing the deleteRow method below, the outerHTML that is displayed in the alert no longer contains the last row. However, the actual row is still displayed on the webpage. if(window.name == 'menuBar') {
8
2042
by: johkar | last post by:
I would like to ensure this script is optimized (runs correctly or does not execute) for the major browsers. Will checking getElementById and getElementsByTagName accomplish this? In addition, I would like adapt it to ignore table headers or rows with existing classes hardcoded. I haven't been able to get the syntax down. Any help appreciated. If there is an existing script that will do all this, that is fine too. I haven't found...
2
4382
by: awebguynow | last post by:
Most JS people have seen sorttable.js and similar implementations. I'm trying to do a SubSelect of an existing table, restricting values in a Column to spec. range. Rows manipulated through sorttable are not copies of the row objects, they are ref's to the tbl row. Therefore care must be taken not to delete them if they are needed, etc. I'm getting used to the API: tbody.deleteRow(rowIndex)
3
18933
by: =?Utf-8?B?UmljaCBIdXRjaGlucw==?= | last post by:
I'm not really sure how to ask this question because I'm still getting my feet wet with data access and VB.NET, but here goes: To start off with, I'm using VB 2005 Express to connect to an Access database. I have a dataset in which a parameterized query returns the correct result set in the forms of a tableadapter and a bindingnavigator. In other words, I can perform my query and see that the tableadapter and bindingnavigator contain...
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10561
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...
1
10302
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,...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
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
6845
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
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.