Call a external js function into another js function

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Apr 2006
Posts: 5
Reputation: Walfort d'Ax is an unknown quantity at this point 
Solved Threads: 0
Walfort d'Ax Walfort d'Ax is offline Offline
Newbie Poster

Call a external js function into another js function

 
0
  #1
Apr 2nd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: Call a external js function into another js function

 
0
  #2
Apr 2nd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5
Reputation: Walfort d'Ax is an unknown quantity at this point 
Solved Threads: 0
Walfort d'Ax Walfort d'Ax is offline Offline
Newbie Poster

Re: Call a external js function into another js function

 
0
  #3
Apr 3rd, 2006
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 17398 | Replies: 2
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC