C
coz
I'm after a little help with a problem I'm been trying to solve for a
few days.
I need to be able to add text to a page at given points (eventually
from an external javascript file). The major problem is that there is
to be no server-side processing as this could be run from the likes of
a CD.
I wish to use an external file so a translator can translate page text
without messing with the page code. So, I'm trying a simple example
such as :
-------------code----------
<script language="JavaScript" type="text/javascript">
<!--
var wordsArray = new Array();
wordsArray[0] = 'Hello';
wordsArray[1] = 'World';
function rewritePage() {
docWords = document.getElementsByTagName("word");
alert(docWords.length);
for (idx=0; idx<docWords.length; idx++)
{
wordNum = docWords[idx].id;
alert(wordNum);
alert(docWords[idx].type);
docWords[idx].innerHTML = wordsArray[wordNum];
}
}
-->
</script>
</head>
<body onLoad="rewritePage()">
<p>Word 1 = <word id="0">bye</word></p>
<p>Word 2 = <word id="1">moon</word></p>
</body>
</html>
--------end code-------
I think the fact that getElementsByTagName returns a collection has got
me really confused.
This only really has to work in IE (unfortunately). The current code
above alerts "2", "0", "undefined","1","undefined" and changes the text
correctly in Firefox but IE aborts after the first "undefined" with
"Undefined Runtime error", which is rather helpful ;-). Is there a
better method someone can suggest?
Feel free to tell me I'm trying to do the impossible, I'd quite
understand.
TIA
Coz
few days.
I need to be able to add text to a page at given points (eventually
from an external javascript file). The major problem is that there is
to be no server-side processing as this could be run from the likes of
a CD.
I wish to use an external file so a translator can translate page text
without messing with the page code. So, I'm trying a simple example
such as :
-------------code----------
<script language="JavaScript" type="text/javascript">
<!--
var wordsArray = new Array();
wordsArray[0] = 'Hello';
wordsArray[1] = 'World';
function rewritePage() {
docWords = document.getElementsByTagName("word");
alert(docWords.length);
for (idx=0; idx<docWords.length; idx++)
{
wordNum = docWords[idx].id;
alert(wordNum);
alert(docWords[idx].type);
docWords[idx].innerHTML = wordsArray[wordNum];
}
}
-->
</script>
</head>
<body onLoad="rewritePage()">
<p>Word 1 = <word id="0">bye</word></p>
<p>Word 2 = <word id="1">moon</word></p>
</body>
</html>
--------end code-------
I think the fact that getElementsByTagName returns a collection has got
me really confused.
This only really has to work in IE (unfortunately). The current code
above alerts "2", "0", "undefined","1","undefined" and changes the text
correctly in Firefox but IE aborts after the first "undefined" with
"Undefined Runtime error", which is rather helpful ;-). Is there a
better method someone can suggest?
Feel free to tell me I'm trying to do the impossible, I'd quite
understand.
TIA
Coz