Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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).

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Solution: 'protected' reserved word in different function

    NikkiH's diagnosis above was spot on. Thread over.

    HD


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •