a newby question

Discussion in 'Javascript' started by Ricardo Garcia, Sep 16, 2004.

  1. hi, i´m starting to use javascript in my web, and i have a quite simple
    question:
    how can i call to a function which is in another .js file, giving it some
    parameters and receiving some data??
    i only knew
    <script type="text/javascript" src="file.js"></script>

    Thanks
    Ricardo Garcia, Sep 16, 2004
    #1
    1. Advertising

  2. Ricardo Garcia

    Lee Guest

    Ricardo Garcia said:
    >
    >hi, i´m starting to use javascript in my web, and i have a quite simple
    >question:
    >how can i call to a function which is in another .js file, giving it some
    >parameters and receiving some data??
    >i only knew
    ><script type="text/javascript" src="file.js"></script>


    If the function is in file.js, you include the line above, and
    then, in a separate <script> tag, invoke the function with your
    parameters. So if the function is myFunction(str), you could use:

    <script type="text/javascript" src="file.js"></script>
    <script type="text/javascript">
    myFunction("Hello, world!");
    </script>
    Lee, Sep 16, 2004
    #2
    1. Advertising

  3. Ricardo Garcia wrote:
    > hi, i´m starting to use javascript in my web, and i have a quite simple
    > question:
    > how can i call to a function which is in another .js file, giving it some
    > parameters and receiving some data??
    > i only knew
    > <script type="text/javascript" src="file.js"></script>


    exactly the same way as if function were in file you're calling function
    from.. as long as JavaScript knows where to find the .js file it'll
    find the function.. goog luck.. Frances
    Frances Del Rio, Sep 16, 2004
    #3
  4. Ricardo Garcia

    Grant Wagner Guest

    Ricardo Garcia wrote:

    > hi, i´m starting to use javascript in my web, and i have a quite simple
    > question:
    > how can i call to a function which is in another .js file, giving it some
    > parameters and receiving some data??
    > i only knew
    > <script type="text/javascript" src="file.js"></script>
    >
    > Thanks


    <head>
    <title>Test</title>
    <script type="text/javascript" src="file.js"></script>
    </head>
    <body>
    <script type="text/javascript">
    someFunctionThatIsDefinedInFileDotJs(parameter1, parameter2);
    </script>
    </body>

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Grant Wagner, Sep 16, 2004
    #4
  5. Ricardo Garcia

    Mark Preston Guest

    Ricardo Garcia wrote:
    > hi, i´m starting to use javascript in my web, and i have a quite simple
    > question:
    > how can i call to a function which is in another .js file, giving it some
    > parameters and receiving some data??
    > i only knew
    > <script type="text/javascript" src="file.js"></script>
    >

    Yes.
    As long as the JavaScript is in the same web-page as the one that calls
    it, it doesn't matter where in the page it is or how it gets there (in
    other words, it can be written in the page or loaded from one or more
    files). Many people put different "snippets" of JavaScript in different
    files - I do myself - and then load them into pages where that snippet
    is to be used.
    Mark Preston, Sep 17, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hermann W Ehlers

    Newby question

    Hermann W Ehlers, May 2, 2004, in forum: ASP .Net
    Replies:
    12
    Views:
    685
    Matt Berther
    May 5, 2004
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    ASP.NET easy newby question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Nov 22, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    452
    Kevin Spencer
    Nov 23, 2004
  3. John Baker
    Replies:
    3
    Views:
    294
    Kevin Spencer
    Feb 8, 2005
  4. John Baker

    Rephrase of Newby Question!

    John Baker, Feb 8, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    552
    Michael C#
    Feb 9, 2005
  5. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    626
    Iain Norman
    Feb 16, 2005
Loading...

Share This Page