Simple javascript ?

Real simple. All I want to be able to do is access variables and functions set in other .js files. Call them dependent files.

Where do you define the ‘dependent files’?

I thought it was like this -

<script language=“javascript” SRC=“ThisIsADependentFile.js” TYPE=“text/javascript”>

It’s driving me nuts. I have looked though both of my javascript books and they don’t mention anything about it.

I’m not sure that you need the type in there.

But you DO need the closing </script> tag in there.

<SCRIPT language=“JavaScript” SRC=“ThisIsADependentFile.js”></SCRIPT>

It’s called “external file” by the way, if you want to google some on it.

Oh, and make sure the path is correct. Putting that on a page has you looking for a file in the same directory as the page you put the call on.

Yep, I’ve got the end </script> Tag in my code. And the correct path.

Neither of my books have a reference for ‘external files’. :mad:

I’ll google.

Using an external javascript.

How do you know that the problem is in the script call? What error are you getting? Maybe the error is in one of the funcs…?

Got it. Thanks everyone. Zipper, I guess you where right.

This works -

<script language=“javascript” SRC=“http://someserver/javascript/aimsXML.js”>
</script>
<script>
testfunction();
</script>

This does not -

<script language=“javascript” SRC=“http://someserver/javascript/aimsXML.js”>
testfunction();
</script>

It works because the first script references the master javascript where all functions are located. The second script is the actual function you are using on the web page from the master javascript.

In other words, you could have this on a web page:
<head>
<script>
Function 1

Function 2

Function 3
</script>
</head>

While in the body you may have:
<body>

Content
<script>
Function 2
</script>
content
<script>
Function 3
</script>
Content
</body>

A different web page using the same functions might only use Function 1 on the page. You avoid having to duplicate all the functions on every web page by creating an external Javascript master document and reference it on every web page. Then, you only use the functions relevant to the page in question. If you choose to add more javascript code, you only add it to the master javascript and select the correct functions for that page.

Clear as mud?

It doesn’t work because you are attempting to do two things at once.

More specifically, this fails becasue the browser either loads the SRC= file , OR processes the “testfunction()’” code, BUT NOT BOTH. Which is processed is browser dependent, but at least in IE 6, the SRC= overrides and so your testfunction() never gets to be part of the page.

Either way, as you say, put them in separate <script></script> tagged blocks & you’ll be A-OK.