0

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?

1 Answer 1

6

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

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

3 Comments

I want to Know call function from One javascript function to another function defined in another script , any idea to declare global function ,Its not the HTML part !,Its Javascript issue
Bjorn's answer looks right to me. Are you not using this in a web page?
venkatachalam there's no special syntax for it required, just call the function.

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.