...

View Full Version : mozilla: script works fine in HEAD, but not in external *.js file



HomelessDave
08-18-2005, 04:17 PM
The facts: I call the changeImages function from the body of the HTML document as follows:

<A HREF="#" ONMOUSEOVER="changeImages('freezeranimationmedium_01', 'images/freezeranimationmedium_01.gif'); return true;" ONCLICK="changeImages('freezeranimationmedium_01', 'images/freezeranimationmedium_01-c.gif');">
<IMG NAME="freezeranimationmedium_01" SRC="images/freezeranimationmedium_01.gif" alt="FreezerCrash" STYLE="border: 2px dashed black;"></A>

The changeImages function is this:

function changeImages() {
if (document.images ) {
for (var i=0; i<changeImages.arguments.length; i+=2) {
document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
}
}
}

The changeImages function sits in an external file HD.js which is referenced in the head of the document as follows:

<SCRIPT SRC="HD.js" type="text/javascript"> </SCRIPT>

The problem: Everything works fine in IE. For Mozilla, I get a 'changeImages is not defined' error on the Javascript console. When I stick the changeImages function right into the head (that is, no external *.js file) Mozilla likes it fine.

Surely there is support for external *.js files for Mozilla?! I'm hoping there's some obvious syntax error that IE forgives but Mozilla does not, which somebody can spot ... the page in question is at www.homelessdave.com/index.htm

Thanks in advance.

Cheers, HD

nikkiH
08-18-2005, 04:37 PM
Firefox also shows this error.

Error: missing formal parameter
Source File: http://www.homelessdave.com/HD.js
Line: 57, Column: 28
Source Code:
function cost(box,scientist,protected) {

The word "protected" is a reserved word. Call it something else.
Fix that first. I bet it makes the other problem go away.

FWIW, the image switch did fine in my Firefox and lagged funny with Avant Browser (IE).

HomelessDave
08-18-2005, 05:11 PM
NikkiH's diagnosis above was spot on. Thread over.

HD



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum