/    Sign up×
Community /Pin to ProfileBookmark

Anyone have a method to do this?

I have the following HTML file.

I want it to select the correct external javascript file to use.
NOTE: Each version of the .js file has same variable names, just different info.

Does anyone know of a way to change the .js file contents to use in the display?

HTML:

[code=php]
<html>
<head>
<title>External JS Re-Loader</title>
<script type=”text/javascript” src=”old.js”></script>
<script type=”text/javascript” src=”new.js”></script>
<script type=”text/javascript” src=”now.js”></script>
<script type=”text/javascript”>
function DisplayJSContents(JSfile) {
alert(‘File to use: ‘+JSfile);
// here is where I would like to select file version to use. ??? HOW ???
var str = ‘Start Date: ‘+StartDate+”n”;
str += ‘Schedule for: ‘+Schedule[0]+”n”;
str += ‘Data display: ‘+Schedule[1]+”n”;
document.getElementById(‘TA’).value = str;
}
</script>
</head>
<body>
<h2>External JS Re-Loader</h2>
<input type=”radio” id=”JSload” name=”JSload” onChange=”DisplayJSContents(this.value)” value=”old.js”>Old
<input type=”radio” id=”JSload” name=”JSload” onChange=”DisplayJSContents(this.value)” value=”now.js”>Now
<input type=”radio” id=”JSload” name=”JSload” onChange=”DisplayJSContents(this.value)” value=”new.js”>New
<p />
Contents of current JS file loaded<br />
<textarea id=”TA” rows=”5″ cols=”30″></textarea>
</body>
</html>
[/code]

External JS file: old.js

[code=php]
// old.js
var StartDate = “06/01/2006”;

Schedule = new Array(“Summer”,”Standard data”);
[/code]

External JS file: new.js

[code=php]
// new.js
var StartDate = “01/01/2007”;

Schedule = new Array(“Spring”,”Standard data”);
[/code]

External JS file: now.js

[code=php]
// now.js
var StartDate = “08/01/2006”;

Schedule = new Array(“Fall”,”Standard data”);
[/code]

Program runs fine without reporting errors.
I just cannot figure out how to reload the different external JS files.

Any ideas are appreciated.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERauthorSep 12.2006 — I'm still trying to figure out how to load different .js files by selection.

One alternative I have thought of since the original post,

but I'm not too sure I want to code it like this,

would be to:

1. Rename the variables in each of the .js files like

var OldStartDate = "06/01/2006"; // old.js file contents

and

var NewStartDate = "01/01/2007"; // new.js file contents

and

var NowStartDate = "08/01/2007"; // now.js file contents

2. Rename "Schedule" as "OldSchedule", "NewSchedule", "NowSchedule"

in each of the .js files

Then copy selected variables to common variable names, as in:

1. StartDate = OldStartDate; // for actions using old.js data

and

StartDate = NewStartDate; // for actions using new.js data

and

StartDate = NowStartdate; // for actions using now.js data

2. Similiar assignments for Schedule from OldSchedule, NewSchedule or NowSchedule as chosen.

I think I can make this work, but this logic would seem to be a waste of memory storage and would slow down the initial loading of the page, so I would like to avoid this method to make my program work.

So I'll ask the forum experts and novice grammers alike,

Can anyone think of a solution that would allow me to selectively load .js files which contain the common variables I wish to access depending upon selection?
Copy linkTweet thisAlerts:
@JMRKERauthorSep 13.2006 — Still looking for suggestions as to how to load different external javascript files.

I know the CSS files can be loaded for different media, so I guess I'm looking for something similiar for a javascript file. The major difference is that I want to load only a selective JS file, not all files at once to be duplicated when I want to access their specific JS file contents.

There seems to be lots of lookers at this topic, but do I have the only viable solution already in the last post?
Copy linkTweet thisAlerts:
@JMRKERauthorOct 12.2006 — Bump.

It's been about a month since I last asked about this topic.

Has anyone got any other ideas about how to do this.

I'm still looking for a more efficient way to do this rather than 'overloading'.
Copy linkTweet thisAlerts:
@KorOct 12.2006 — If you want to load, asyncronousely, small pieces of data on will, you may put your data in XML files and use AJAX
Copy linkTweet thisAlerts:
@JMRKERauthorOct 12.2006 — Thanks for the information.

I did not know if it could be done.

I will look into the XML and AJAX subjects as I am not very familiar with them yet!
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...