a newby question

R

Ricardo Garcia

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
 
L

Lee

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>
 
F

Frances Del Rio

Ricardo 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>

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
 
G

Grant Wagner

Ricardo 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>

Thanks

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

Mark Preston

Ricardo 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>
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top