Codeasearch.com - Search your code with us Login | Register | Contact us
  Forums > Javascript > How to include or use external javascript functions or variables in another javascript file.
najeebputhiyallam
Posted on Jun 28, 2009
Join Date: March 2009
Location: India ( Bangalore )
Posts: 12
 
How to include or use external javascript functions or variables in another javascript file.  

Hi guys i want to access a variable or function from another JavaScript File to another JavaScript File..

PS: In PHP we use INCLUDE or REQUIRE to do it.

kevin
Posted on Jun 29, 2009
Join Date: May 2008
Location: India ( chennai )
Posts: 4978
 
RE : How to include or use external javascript functions or variables in another javascript file.  

Hi,
First create one html or php file then copy and paste below code.

<script language="javascript">
var strValue = "How are you...";
</script>

Then create another file called demo.js in that file copy and paste below code
alert("Hi, "+strValue);

Now include javascript in the html or php file like below
<script language="javascript">
var strValue = "How are you...";
</script>
<script language="javascript" src="demo.js"></script>

We declare global so we can access it anywhere.

 Hot Discussion
Go Tech launches Android tablet for Rs 3,999...
Sony targets retailers with quick sales pitches and rew...
Share and discover new activities with Google Schemer...
Samsung gets 9 mn preorders for Galaxy S3: Report...
Google revamps search engine to think like a person...
 
 Discussion Topics
IT News
Php
Javascript
Technology Updates
Asp.Net
MySql
Ajax
Html
Fedora
Software Testing
Asp
Java
General
Flash
Ruby on Rails