This is a newbie question. I have two javascript and one html files. When I click on an image it goes to the first .js file and when it finnish to run all that code should go to the second .js file. But how can I connect the two functions that are in different files.
thanks
This is a newbie question. I have two javascript and one html files. When I click on an image it goes to the first .js file and when it finnish to run all that code should go to the second .js file. But how can I connect the two functions that are in different files.
thanks
Share Improve this question asked Jul 18, 2011 at 14:34 saomisaomi 8955 gold badges18 silver badges41 bronze badges 1- What do you mean by "it goes to the first .js file" and "should go to the second .js file"? Do you want to call the two functions with the same image passed as a parameter? – Jose Faeti Commented Jul 18, 2011 at 14:38
4 Answers
Reset to default 3you need just to define the 2 js files in the HTML header page :
<script type="text/javascript" src="one.js"></script>
<script type="text/javascript" src="second.js"></script>
It doesn't matter what files the functions are in, you can call the second function from the first one.
You should also consider why you are separateing your functions into seperate files - in general, they should all be in as few files as possible.
Like so:
In file1.js:
var foo = function(){
bar();
};
In file2.js:
var bar = function(){
alert('hello');
};
You will have something like this,
in the html file:
<input type="button" name="" onclick="random1();" />
in the first js file:
function random1(){
// your code here
random2();
}
in the second js file:
function random2(){
//your code here
}