Question

I have Designed the Javascript function My.js it contains following code

My.js
function display(){

  //Call to another Javascript function defined as ShowUser() in selectUser.js
  showUser(str);

 }



SelectUser.js has


 function showUser(Str){

     //Do the display

 }

Now, my question is: I want to call showUser() from My.Js itself. Any one suggest how to make the call? Should I include anything?

Was it helpful?

Solution

You need to have separate script tags with the src attribute set for both javascript files in your HTML document, assuming this is for an HTML page (and not an AIR app, or serverside JavaScript, or Rhino). Whatever functions you declare in the global scope in any JavaScript file you add via a script element, or inline code should be available to JavaScript in any file.

The only caveat to this is that if you use window.foo syntax to assign something to the global (window) scope in a file then, surprisingly in IE, other files will think window.foo is unassigned until JavaScript begins executing.

More Info on that last issue

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top