ddawson7
ddawson7

Reputation: 1

Import variable values from an external JS file

I have a JS file located in directory c:\myJSfiles\FileNumberOne.xyz

    //c:\myJSfiles\FileNumberone.xyz 

    var 1 = ThisValue1;
    var 2 - ThisValue2;
    and so on

In the same root directory, I have second JS file c:\myJSfiles\FileNumberTwo.xyz which I want to import the values of the variables from FileNumberOne.xyz

    //file: c:\myJSfiles\FileNumberTwo.xyz

    var A = "c:\myJSfiles\FileNumberOne.xyz", var 1;
    var B = "c:\myJSfiles\FileNumberOne.xyz", var 2;

How would I do this?

Upvotes: 0

Views: 179

Answers (1)

Yuriy Galanter
Yuriy Galanter

Reputation: 39807

var 1 makes no sense, I assume you did it as an example only. Otherwise if you declare something in the first referenced script on the page, it will automatically be available in the second.

for example if you have in

<script src="Script1.js"></script>

line

var something = "hello"

you can reference the second script after the first

<script src="Script2.js"></script>

and in that script use that variable

alert(something); // will display hello

Upvotes: 1

Related Questions