Craig Strickland

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromCraig Strickland
ToMe
SubjectProblem with DOM browser support
Date20 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.
FromMe
ToCraig Strickland
SubjectRe: Problem with DOM browser support
Date20 September 2005 19:03
Craig,

Please test all required browsers, and tell me what happens
FromCraig Strickland
ToMe
SubjectRe: Problem with DOM browser support
Date20 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
FromMe
ToCraig Strickland
SubjectRe: Problem with DOM browser support
Date20 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/
FromCraig Strickland
ToMe
SubjectRe: Problem with DOM browser support
Date20 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!
FromMe
ToCraig Strickland
SubjectRe: Problem with DOM browser support
Date18 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?
FromCraig Strickland
ToMe
SubjectRe: Problem with DOM browser support
Date20 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>
-------------------------------------------------------------------------
FromMe
ToCraig Strickland
SubjectRe: Problem with DOM browser support
Date20 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
FromCraig Strickland
ToMe
SubjectRe: Problem with DOM browser support
Date20 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.
FromCraig Strickland
ToMe
SubjectRe: Problem with DOM browser support
Date20 September 2005 21:34
Interesting...no browser will allow multiple entries...
FromCraig Strickland
ToMe
SubjectRe: Problem with DOM browser support
Date21 September 2005 14:39
Got it! Had some arguments to correct!

Thanks again for your help.
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.