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
    Registered User
    Join Date
    Dec 2004
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Loading External file in JavaScript

    Hi, I'm having trouble opening an external JS file to be executed as an array.

    For example the following DOES NOT WORK:

    Code:
    var whatever ('<SCRIPT LANGUAGE="JavaScript" SRC="external_file.js"><\/SCRIPT>');

    What is wrong with this and why is it not pulling up the external file?

    Thanks in adavance.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    an array?

    an array can be:
    var whatever =[string]
    or
    var whatever = new Array(string)
    or
    var whatever = new Array()
    whatever[0] = string;

    What is your goal, anyway?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Canada, eh?
    Posts
    133
    Thanks
    2
    Thanked 3 Times in 3 Posts
    ACTUAL help:

    External JS files are simply files that contain JS that is executed when it is called. You cannot, for example, put specific data into a JS file and then expect it to load as that data into whatever value you specify.

    If you want to include an array from an external file, then you must include that array as code in the external file. If you want to change the name of the array, then you can just re-assign the array to another variable.


    external_file.js:

    Code:
    whatever = new Array();
    whatever[0] = "Hi mom!";
    whatever[1] = "...";
    And then include it SIMPLY with a script tag:

    Code:
    <script type="text/javascript" src="external_file.js"></script>
    Now after that is called, the variable "whatever" is the array.



    If (for some reason) you wanted the array to take on whatever variable name you wanted, then you would do the exact same for the external file, but then you would assign the new variable to the array variable. Like so:

    Code:
    some_variable = whatever;
    Now "some_variable" is equal to the array.


  •  

    Posting Permissions

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