0

In file1.js inside a function I need to call a function which is actually included in file2.js

How can I do it?

Thank you

Later edit: This is what I want:

function back(){
if (step!=0){
dijit.byId('stackContainer').back();
}else{
//here I should call the save() function from file2.js
}
}

0

5 Answers 5

3

If you have multiple js files, you simply include all the files in the html page that you are using to call them. since javascript is globalised once you include it, you can call methods from another js file from a particular js file as long as both js files are included in the page.

Sign up to request clarification or add additional context in comments.

Comments

3

Include both the js files in the same document. Then you can call one function in a js file from the other one.

Comments

2

You need to include both of the javascript files in the same HTML page:

<script type="text/javascript" src="file2.js"></script>
<script type="text/javascript" src="file1.js"></script>

Comments

2

You simply need to be careful with the ordering of the javascript file includes. Make sure that the file containing the function you want to call is included in the document first. Once the function is defined, it can be used.

Comments

1
<script type="text/javascript" src="file2.js"></script>
<script type="text/javascript" src="file1.js"></script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.