Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic js load part 2

Status
Not open for further replies.

SirEddy

Programmer
Oct 24, 2005
10
US
ok let me try this again cause a variable was posted wrong before and I don't want the to confuse things. Below is a complete html plus the js file being loaded. This works on a local basis but not when uploaded on my site.

--------------------------------------------------------
<HTML>
<HEAD>
<TITLE>No Title Yet</TITLE>

<SCRIPT type=text/javascript>
function loadJSscript(TheFile){
jsscriptFileNameFinal=TheFile;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = jsscriptFileNameFinal;
document.getElementsByTagName('head')[0].appendChild(script);
alert(TopicsList)
}
</SCRIPT>

</head>

<BODY onload="loadJSscript('d_Formats_VRML.js')">
Testing
</BODY></HTML>

--------------------------------------------------------
THE js file 'd_Formats_VRML.js'

var TopicsList = [
["Avatars"],
["Browser"],
["Games"],
["Interactive Worlds"],
["Medical"],
["Models"],
["Science"],
["Worlds"]
];

majorTopic="Formats"
mainTopic="VRML"

alert("TopicsVRML.js Loaded")
--------------------------------------------------------

Notice the "alert(TopicsList)" that should fire back the array in the js file. It does not when uploaded to web site. However, it does when all is local.
 
Is the host you're using running a case sensitive OS, or Windows? Mixing upper and lower case letters in a name is often the cause of problems when moving from a Windows environment to some flavor of UNIX.

Lee
 
Well a very great thought. So I went back to beating my head against the wall and pretty much the same outcome.

I get the alert("TopicsVRML.js Loaded") telling me it is hitting the js file BUT I do not get the alert(TopicsList)
telling me the array is not be recognized.

I am at a complete loss.
 
It is probably a timing issue. At no stage are you waiting for the JS file to load before assuming you can call functions / access variables in it.

Why not simply put the JS file include hard-coded onto the page (rather than use JS to include JS0, and use the onload event to do this? You've not said why you do not want to / cannot do this.

Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Well that is an interesting reply.

OK what I am trying to do is simply a flat database. However I do not want to load all the data at one time. Although specific sections of data will be small (most likely) I want to load the data on demand. Also to keep the coding as simple as possible I am using the same variable in each js data file so that TopicList will be the variable processed:

var TopicsList = [
This array is changed for multiple js data files but the code processes the variable TopicList for example.
];

Dan I think you have a very valid point here. My new question is how to be sure that the array has been fully loaded before calling it.

From all I see here the code is correct and the host seems to not be concerned with uppercase lowercase problems but I am not 100% sure of that yet.
 
At the end of the dynamic JS file you include, you could have something like:

Code:
DynamicFileLoaded();

and then on the page that includes the file, you could have a function:

Code:
function DynamicFileLoaded() {
   alert(TopicsList);
}

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Well I have yet to noodle through that solution but it does work. Thank ya so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top