Solved

Traversing the DOM in IE6

Posted on 2008-10-15
3
1,685 Views
Last Modified: 2013-11-18
I receive this error:
childNodes.1.childNodes.1.childNodes is null or not an object

for the attached code snippit in IE 6... the code works fine in IE 7 and FireFox 2... but not in IE 6 if anyone can point me out some tips, I'd be greatly appreciative.
var oldSelectRow = selectRow;
selectRow = function(object, selectionType, hasControl, index, duringPageLoad, disableDeselect) {
    var theRow = object;
    while (theRow.nodeName != 'TR') {
      theRow = theRow.parentNode;
    }
    document.getElementById("InputText0").value = theRow.childNodes[1].childNodes[1].childNodes[1].childNodes[1].innerHTML; //This is where the error occurs according to IE 6
	oldSelectRow(object, selectionType, hasControl, index, duringPageLoad, disableDeselect);
}

Open in new window

0
Comment
Question by:jabrthel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 22728762
Please show the complete html
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 22729511
Try adding code that displays information about the individual elements.
For example, perhaps something like:
<script type='text/javascript' src='objDisplay.js'></script>
 
...
  alert( objDisplay( 'thisRow', thisRow ) );
...
  alert( objDisplay( 'child[1]', thisRow.child[ 1 ] ) );
...

Open in new window

objDisplay.js.txt
0
 
LVL 42

Accepted Solution

by:
David S. earned 250 total points
ID: 22736313
This seems to be the standard issue of IE not counting white-space only text nodes in the childNodes collection.  One way to solve the issue is to use the following function instead of childNodes directly.
@Michel and HG: Wow. No offense, but I'm surprised that you both missed the problem.

function getChildNode(elm,num,type) { // 2nd and 3rd args are optional
  num=num||0;type=type||1; // by Kravvitz of DynamicSiteSolutions.com
  var i=-1,n=elm.childNodes,l=n.length,k=-1;
  while(++i<l) if(n[i].nodeType==type && ++k==num) return n[i];
  return null;
}

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question