View Full Version : Loading External file in JavaScript

05-25-2005, 01:57 AM
Hi, I'm having trouble opening an external JS file to be executed as an array.

For example the following DOES NOT WORK:

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.

05-25-2005, 12:02 PM
an array?

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

What is your goal, anyway?

Eternity Angel
05-25-2005, 06:02 PM
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.


whatever = new Array();
whatever[0] = "Hi mom!";
whatever[1] = "...";

And then include it SIMPLY with a script tag:

<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:

some_variable = whatever;

Now "some_variable" is equal to the array.