942,967 Members | Top Members by Rank

Ad:
Apr 2nd, 2006
0

Call a external js function into another js function

Expand Post »
Dear All,

In my "Javascripts\english" folder I have language related javascript files. In one of these files there is a function I want it to get the return value of a function getChangedDate() from a general Javascript file called changes.js in my "Javascripts" folder.
I also want to use the same getChangedDate() function in from my "Javascripts\français", "Javascripts\italiano", "Javascripts\deutsch", "Javascripts\nederlands", ... folders.

How can I get this return value?
Someone suggested this soluton:

load("../changes.js") ;
changedDate = getChangedDate() ;

I also tried
load("/Javascripts/changes.js") ;
changedDate = getChangedDate() ;

or
load("\Javascripts\changes.js") ;
changedDate = getChangedDate() ;

or
load("..\changes.js") ;
changedDate = getChangedDate() ;

Non of these work, probably because there is not such a thing as a standard load() function.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Walfort d'Ax is offline Offline
5 posts
since Apr 2006
Apr 2nd, 2006
0

Re: Call a external js function into another js function

There are several things you can do... for example it is possible to dynamically add and remove html nodes from your page using javascript. But I find this isn't particularly quick (sometimes you need to wait before you try and call a newly loaded script - using setTimeout or similar).

But I think there are a couple of simple solutions to your problem - either using some kind of server side technology to decide on language and draw the page to fit... or write a global interface to your language files. So you only have one function getChangedDate() , but this calls a specific getChangedDate() based on a global variable.. i.e.

function getChangedDate() { changedDate = (language == english)?getEnglishChangedDate():getFrenchChangedDate() ; }

Another solution I'd like is to use JavaScript Classes. This would give you the ability to keep the method naming, but you'd still need some logic...

function getChangedDate() { changedDate = (language == english)?English.getChangedDate():French.getChangedDate() ; }

I'd say the best practise would be to use a server side based solution, unless this is not available to you.
Reputation Points: 20
Solved Threads: 5
Junior Poster
alpha_foobar is offline Offline
182 posts
since May 2005
Apr 3rd, 2006
0

Re: Call a external js function into another js function

Quote originally posted by alpha_foobar ...
There are several things you can do... for example it is possible to dynamically add and remove html nodes from your page using javascript. But I find this isn't particularly quick (sometimes you need to wait before you try and call a newly loaded script - using setTimeout or similar).

But I think there are a couple of simple solutions to your problem - either using some kind of server side technology to decide on language and draw the page to fit... or write a global interface to your language files. So you only have one function getChangedDate() , but this calls a specific getChangedDate() based on a global variable.. i.e.

function getChangedDate() { changedDate = (language == english)?getEnglishChangedDate():getFrenchChangedDate() ; }

Another solution I'd like is to use JavaScript Classes. This would give you the ability to keep the method naming, but you'd still need some logic...

function getChangedDate() { changedDate = (language == english)?English.getChangedDate():French.getChangedDate() ; }

I'd say the best practise would be to use a server side based solution, unless this is not available to you.
Thanks for your reply,
It's worth studying your suggestion
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Walfort d'Ax is offline Offline
5 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: How to enable or disable Internet Explorer tool bar buttons using javascript
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Error reading XML file in Javascript





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC