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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Arrays in a function

    Hello
    I'm beginner of java scripting and have a little problem

    In my html file i define a array

    Code:
    mypics=new Array(
    "images/zulauf_100.jpg",
    "images/zulauf_450_S.jpg",
    
    "images/ablauf_100.jpg",
    "images/ablauf_450_S.jpg"
    )
    in a separate javascriptfile i have a function
    Code:
    function doanything()
    {
      i=0;
      anzahl=mypics.length;
      while (i < (anzahl))
       {
         document.writeln(mypics[i] + "<br>");
         i++;
       }
    
    }
    but this not work.
    If both codings in the same htmlfile it works.
    may be it works there because the array is global.

    I think the problem is to transfer this array conntent to an external function.
    How is the right way to transfer an array to a function in a separate javascriptfile

    thanks

    Susanna

  • #2
    New Coder
    Join Date
    Jul 2002
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    change your function to this:
    ------------------------------------
    function doanything(array)
    {
    for (i=0; i < array.length; i++)
    {
    document.writeln(array[i] + "<br>");
    }
    }

    and call it using this syntax:
    ----------------------------------
    doanything(mypics);

    Later,
    V


  •  

    Posting Permissions

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