By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,693 Members | 1,754 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,693 IT Pros & Developers. It's quick & easy.

a newby question

P: n/a
hi, im 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
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

Ricardo Garcia wrote:
hi, im 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

Jul 23 '05 #2

P: n/a
Ricardo Garcia wrote:
hi, im 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 <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #3

P: n/a
Lee
Ricardo Garcia said:

hi, im 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>

Jul 23 '05 #4

P: n/a
Ricardo Garcia wrote:
hi, im 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.
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.