-1

I am having a function like this in one of the script file,

function ex(data){
//do something
}

I want to call this function from another script file with parameters. What should be the correct approach? I went through this which is having many solutions, I tried them all but all are working in mozilla only.

Also I am new to javascript/jquery so please pardon my silly mistakes if any.

Community
  • 1
  • 1
iknownothing
  • 57
  • 1
  • 2
  • 4
  • You need to include the `script file` where the above `function` exists, before the `script file` where you are calling this `function` – Guruprasad J Rao May 24 '16 at 07:35
  • Make sure your `ex` function is under global scope.. – Rayon May 24 '16 at 07:36
  • I assume `window.ex()` throws a TypeError? Use some developer tools to debug. – shennan May 24 '16 at 07:37
  • Why you give a -1 to this question? Really I don't understand. He's a novice javascript programmer and he's using stack overflow to understand and learn new things. – Ema.jar May 24 '16 at 07:48

1 Answers1

-1

You should do something like that:

first.js

function ex(number) {
    alert(number);
}

second.js

function otherFunction() {
     ex("two");
}

Now you should include these two js files in your HTML:

<script type="text/javascript" src="first.js"></script>
<script type="text/javascript" src="second.js"></script>
<script type="text/javascript">
    otherFunction( );
</script>
Ema.jar
  • 2,370
  • 1
  • 33
  • 43