a newby question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ricardo Garcia

    a newby question

    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


  • Frances Del Rio

    #2
    Re: a newby question


    Ricardo Garcia wrote:[color=blue]
    > 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>[/color]

    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

    Comment

    • Grant Wagner

      #3
      Re: a newby question

      Ricardo Garcia wrote:
      [color=blue]
      > 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[/color]

      <head>
      <title>Test</title>
      <script type="text/javascript" src="file.js"></script>
      </head>
      <body>
      <script type="text/javascript">
      someFunctionTha tIsDefinedInFil eDotJs(paramete r1, parameter2);
      </script>
      </body>

      --
      Grant Wagner <gwagner@agrico reunited.com>
      comp.lang.javas cript FAQ - http://jibbering.com/faq

      Comment

      • Lee

        #4
        Re: a newby question

        Ricardo Garcia said:[color=blue]
        >
        >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>[/color]

        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("Hel lo, world!");
        </script>

        Comment

        • Mark Preston

          #5
          Re: a newby question

          Ricardo Garcia wrote:[color=blue]
          > 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>
          >[/color]
          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.

          Comment

          Working...