HighDots Forums  

How do I call a function from another .js file?

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss How do I call a function from another .js file? in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Snoopie
 
Posts: n/a

Default How do I call a function from another .js file? - 08-03-2006 , 08:36 AM






i have 2 .js files, mpi.js and functions.js
the functions.js file contains common functions that i reference from
my web pages. i have a function in mpi.js that needs to call one of
the functions from functions.js but i dont know how to do this.
if memory serves me in Java you had to use the import statement, but
that does not appear to work in this case.

Snoopie

Reply With Quote
  #2  
Old   
Snoopie
 
Posts: n/a

Default Re: How do I call a function from another .js file? - 08-03-2006 , 08:48 AM






On Thu, 03 Aug 2006 13:36:10 GMT, Snoopie <none (AT) ya (DOT) biz> wrote:

Quote:
i have 2 .js files, mpi.js and functions.js
the functions.js file contains common functions that i reference from
my web pages. i have a function in mpi.js that needs to call one of
the functions from functions.js but i dont know how to do this.
if memory serves me in Java you had to use the import statement, but
that does not appear to work in this case.

Snoopie
ha, i answered my own question

the code is as follows

in the mpi.js i just needed to add

// include functions.js
document.write("<script language='Javascript' type='text/javascript'
src='scripts/functions.js'></script>");

note that i keep my scripts in a subfolder called scripts

i hope this helps out someone else

Snoopie


Reply With Quote
  #3  
Old   
tia
 
Posts: n/a

Default Re: How do I call a function from another .js file? - 01-20-2007 , 08:27 AM



Snoopie wrote:
Quote:
On Thu, 03 Aug 2006 13:36:10 GMT, Snoopie <none (AT) ya (DOT) biz> wrote:

i have 2 .js files, mpi.js and functions.js
the functions.js file contains common functions that i reference from
my web pages. i have a function in mpi.js that needs to call one of
the functions from functions.js but i dont know how to do this.
if memory serves me in Java you had to use the import statement, but
that does not appear to work in this case.

Snoopie

ha, i answered my own question

the code is as follows

in the mpi.js i just needed to add

// include functions.js
document.write("<script language='Javascript' type='text/javascript'
src='scripts/functions.js'></script>");

note that i keep my scripts in a subfolder called scripts

i hope this helps out someone else

Snoopie
Just want to add this - don't make the mistake of thinking that
Javascript has anything at all to do with Java. It doesn't.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.