www.webdeveloper.com
Results 1 to 3 of 3

Thread: How to call a function in one .js file from another .js file

  1. #1
    Join Date
    Mar 2006
    Posts
    28

    How to call a function in one .js file from another .js file

    Hello Techies,
    I am trying to call a function in two.js file from one.js file.

    Here is my code
    one.js

    <script>

    document.write("<script type='text/javascript' src='/htmls/js/two.js'> <\/script>");
    function one()
    {
    var a;
    two(a);
    }



    two.js
    function two(a)
    {
    alert("two");
    }


    But the function two() is not working.
    How can I do this one??

  2. #2
    Join Date
    Dec 2004
    Posts
    8,637
    If both .js files are correctly included in the same document, then there will be no problem calling a function in the other .js file. Effectively, once the two files are included in the same document, it is as if they were always in the same document. There is no distinction, at that point, as to which .js file they originally came from.

  3. #3
    Join Date
    May 2003
    Location
    O!
    Posts
    200
    When the document.write statement is executed, that is all that the browser will do. It won't execute the write and then the load.

    What you want to do is something like:
    Code:
    <script type='text/javascript' src='/htmls/js/two.js'></script>
    <script type='text/javascript'>
    function one()
    {
     var a;
     two(a);
    }
    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles