parentNode Not Implemented?!?

D

DanielLinn

I'm getting an error in IE 6.0.2800 that says "Error: Not implemented."
when I try to get a parent. Does it whether or not 'compatibility
mode' is on.

Here's my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>User Results</title>
<link href="css/screen.css" rel="stylesheet" media="all" />
<script type="text/javascript" language="javascript">
function highlightRow(elem) {
alert(elem.parentNode.parentNode.id);
parent = findOwner( elem );
parent.className = "highlighted";
}
function findOwner( elem )
{
var node = elem;
while (node)
{
if ( node.nodeType == node.ELEMENT_NODE && node.nodeName == "TR")
{
alert("found it");
return node;
}
node = node.parentNode;
}
alert("didn't find it");
return null;
}
</script>
</head>
<body>
<table cellspacing="0" id="scrollMe" class="formdata">
<tr id="rowThing">
<td class="center command" id="tdThing"><input id="testingThis"
type="checkbox" class="checkEm" name="vehIndex_0"
onclick="highlightRow(this);" value="0"/>
</td>
</tr>
</table>
</body>
</html>

What's odd is that the first alert will return the proper ID of the row
(using parentNode), but when I use parentNode to assign the parent to a
var, it chokes. Works fine on Moz (surprise, surprise). Any ideas?
 
R

RobG

I'm getting an error in IE 6.0.2800 that says "Error: Not implemented."
when I try to get a parent. Does it whether or not 'compatibility
mode' is on.

Because that is irrelevant to the error :)
Here's my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

It is pointless to try using XHTML with IE, it will treat it as HTML
anyway. Stick to 4.01 strict unless you have some really special
reason to use XHTML, in which case IE becomes irrelevant.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>User Results</title>
<link href="css/screen.css" rel="stylesheet" media="all" />
<script type="text/javascript" language="javascript">

The language attribute is long since deprecated, just remove it.

function highlightRow(elem) {
alert(elem.parentNode.parentNode.id);
parent = findOwner( elem );

Here you create 'parent' as a global variable, but not until
higlightRow is executed. This is what is actually causing your problem
- IE will not assign the result if the right hand side expression to
it. You can declare parent anywhere - either global or local, local is
better unless you have a reason for it to be global - and your issue
goes away.

parent.className = "highlighted";

Since findOwner can return null if a TR isn't found, you should test
the returned value - what is the effect of adding a className property
to the null object?

}
function findOwner( elem )
{
var node = elem;
while (node)
{
if ( node.nodeType == node.ELEMENT_NODE && node.nodeName == "TR")

I can't understand why you bother with the first test - it creates a
dependency on DOM 3 that doesn't seem necessary and is not supported by
my IE 6 - it never finds the TR. Go back to HTML and DOM 2.

If you want this to work on the web, just test the node name since it
is sufficient for your purpose and much more widely supported.

Since you are pretending to use XHTML, you should follow the advice in
the W3C specs and compare node names (and tag names too for that
matter) using lower case:

if (node.nodeName && node.nodeName.toLowerCase() == 'tr' ){
/* found an HTML TR node */
}


[...]
var, it chokes. Works fine on Moz (surprise, surprise). Any ideas?

Not really a surprise that it works in Mozilla, which has much better
support for DOM 3 than IE.

What you are seeing is likely a bug in IE that it doesn't correctly
assign a value to 'parent' - since it never finds the TR element, it
should be assigned 'null' (maybe you are using IE 7 and it does support
it, I dunno).
 
D

DanielLinn

Holy geez. That's the most complete and helpful response to a post
I've ever had. Thanks for your help Rob. Now i'm going to go sulk in
the corner and read the standards again ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top