Email conversation
From | Craig Strickland |
To | Me |
Subject | Problem with DOM browser support |
Date | 20 September 2005 18:59 |
Hello,
Can you tell me why this syntax works in Internet Explorer and not in Netscape 7.1?
I'm trying to update a dom element value and it fails on the second onchange in Netscape.
<script>
function myonchangeevent( id, v )
{
var z = document.getElementById( id ).innerHTML = v;
}
</script>
Thanks!
Craig
PS...you site is very helpful.
From | Me |
To | Craig Strickland |
Subject | Re: Problem with DOM browser support |
Date | 20 September 2005 19:03 |
Craig,
Please test all required browsers, and tell me what happens
From | Craig Strickland |
To | Me |
Subject | Re: Problem with DOM browser support |
Date | 20 September 2005 19:14 |
I only have access to Netscape and IE here.
When I try to read the element.innerHTML after the
second onchange, the value is blank in Netscape and
correct in IE. I get the error:
uncaught exception: [Exception..."Component returned failure code:
0x80004005 (NS_ERROR_FAILURE)[nsIDOMNSHTMLElement.innerHTML]"
The element appears to become null however the html on the
screen does not change.
Thanks tremendously for your help.
Craig
From | Me |
To | Craig Strickland |
Subject | Re: Problem with DOM browser support |
Date | 20 September 2005 19:26 |
Craig,
> I only have access to Netscape and IE here.
And prey tell, why can you not test in Opera? It is a free download:
http://www.opera.com/download/
> uncaught exception: [Exception..."Component returned failure code:
> 0x80004005 (NS_ERROR_FAILURE)[nsIDOMNSHTMLElement.innerHTML]"
That error message is completely useless I am afraid. I really do prefer
Opera's JavaScript console messages. They are so much more helpful.
Anyway, please sent me a URL where I can see the error for myself. At the
same time, please test in Opera and tell me what Opera says.
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
From | Craig Strickland |
To | Me |
Subject | Re: Problem with DOM browser support |
Date | 20 September 2005 19:54 |
Works in Opera!
I'm confused now...Netscape hates me...
My users will only have Netscape and IE and I don't want
to limit them to IE.
btw...I do like Opera!
From | Me |
To | Craig Strickland |
Subject | Re: Problem with DOM browser support |
Date | 18 September 2005 20:02 |
> Works in Opera!
>
> I'm confused now...Netscape hates me...
ok, so I need to see the real page. can you put it online?
From | Craig Strickland |
To | Me |
Subject | Re: Problem with DOM browser support |
Date | 20 September 2005 20:38 |
Here's a snippet example of the failing code:
The second alert is blank in Netscape; the "var m..."
is blowing away the innerHTML in Netscape
-------------------------------------------------------------------------
<html>
<head>
<script>
function f_update( i, v )
{
alert('first alert = ' + document.getElementById( i ).innerHTML);
var m = document.getElementById( i ).innerHTML = "<input type=text
id=mycell onChange=f_update(this.id) value='" + v + "'>";
alert('second alert = ' + document.getElementById( i ).innerHTML);
}
</script>
</head>
<body>
<div>Enter text and the move focus to the other field</div>
<form name=myform>
<table id='tblSample1'>
<tr>
<td id='mycell'>
<input type=text id='mycell' onChange='f_update(this.id,
this.value)' value=''>
</td>
<td id='mycell1'>
<input type=text id='mycell1' onChange='f_update(this.id,
this.value)' value=''>
</td>
</tr>
</table>
</form>
</body>
</html>
-------------------------------------------------------------------------
From | Me |
To | Craig Strickland |
Subject | Re: Problem with DOM browser support |
Date | 20 September 2005 20:57 |
Craig,
Ok, I got it:
> <td id='mycell'>
> <input type=text id='mycell' onChange='f_update(this.id,
> this.value)' value=''>
That is invalid. Two elements are not allowed to share the same ID. The ID _must_ be
unique within a document.
IE and Opera both manage to guess what you meant, Gecko does not.
Give the cell and input different IDs (and make sure you pass the right ID
to f_update) and it should work. Something like this:
<td id='mycell'>
<input type=text onChange='f_update(this.parentNode.id,this.value)'
value=''>
</td>
Tarquin
From | Craig Strickland |
To | Me |
Subject | Re: Problem with DOM browser support |
Date | 20 September 2005 21:13 |
Thanks...for me it still fails with Netscape 7.1
hmmm....
I do understand that the id's should be unique even
though they're in a different branch of the tree.
From | Craig Strickland |
To | Me |
Subject | Re: Problem with DOM browser support |
Date | 20 September 2005 21:34 |
Interesting...no browser will allow multiple entries...
From | Craig Strickland |
To | Me |
Subject | Re: Problem with DOM browser support |
Date | 21 September 2005 14:39 |
Got it! Had some arguments to correct!
Thanks again for your help.