Error if I remove Alert ?!

S

sarah.ali1

I had an alert statement in my code for debugging purposes. However if
I try to remove the line of code with the alert statement in it (
alert('message') ), I get an error in my code!

Any ideas?
 
S

sarah.ali1

Here is the function with the code:

function Start1(event) {

include("phase.js"); // a function that includes an external javascript
file on the fly
include("answerkey.js");

alert('debug message') //<---THIS is the problem, if i remove this
line, I get an error

getPhases(); //another function which works fine as long as the alert
is there

}

Any help would be great
 
R

RobG

Here is the function with the code:

function Start1(event) {

include("phase.js"); // a function that includes an external javascript
file on the fly

And that is the real code in question. How does include() actually
include the script file? The best method is:

function loadJSFile(fileURL){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.src = fileURL;
document.getElementsByTagName('head')[0].appendChild(newScript);
}

<URL:
http://groups.google.com/group/comp...=load+external+script&rnum=7#6f16ebc326f0eb9a

I'm not keen on using 'include' as the name of the function, it's not a
reserved word but it may be misleading for those who come from another
programming environment.
 
R

Randy Webb

(e-mail address removed) said the following on 7/30/2006 8:39 PM:
Here is the function with the code:

function Start1(event) {

include("phase.js"); // a function that includes an external javascript
file on the fly
include("answerkey.js");

alert('debug message') //<---THIS is the problem, if i remove this
line, I get an error

getPhases(); //another function which works fine as long as the alert
is there

}

Any help would be great

It is a timing issue where you are trying to call a function in the
external file before that file gets loaded.

The browser won't wait for that file to load before continuing. The
alert pauses the script execution long enough for the file to load and
then you get no errors. Removing the alert removes that pause so you get
the error.

It is not the alert that is stopping the error but rather it is the stop
in execution caused by the alert that prevents the error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top