Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within HTML Pages with CSS and JavaScript
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
HTML Pages with CSS and JavaScript
javascript import
Stu Johns
Ranch Hand
Posts: 63
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi, I have 2 javascript files
test1.js and test2.js
I want to call a function in test1.js from a function in test2.js
So i need to do something similar to a
java
import.
Can this be achieved?
thanks
Stu.
Jason Marlyn
Ranch Hand
Posts: 90
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
it's easy to call a function from another function
for example function a() from 1.js want call function x() from 2.js
OK look
code for a():
function a(){ alert("I want call x() method from 2.js"); var R=x(); document.write("result of x() method is "+R); }
and code for x():
function x(){ var e=prompt("set a result to pass to method a()","ArAsh"); return e; }
so as you see calling methods(functions) not so hard
and about link(import) 1.js and 2.js to document
it's as easy as ABC
just in your head add these guys
<script type="text/javascript" src="somewhere/somefolder/1.js"></script> <script type="text/javascript" src="somewhere/somefolder/2.js"></script>
Open source
Stu Johns
Ranch Hand
Posts: 63
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thats great, thanks.
Stu
Bear Bibeault
Sheriff
Posts: 67746
173
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Once both files are included in the page, they all become part of the same scope.
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
Eric Pascarello
author
Posts: 15385
6
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If you are not sure that a file is added you can do a simple check
if(typeof foo !== "undefined"){ alert("nope"); }
and you can add it in with document.createElement
Eric
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Javascript Variable scope
Regarding Package
Question about document ready block
js references/garbage collection/other questions
More...