Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Error if I remove Alert ?!

Reply
Thread Tools

Error if I remove Alert ?!

 
 
sarah.ali1@gmail.com
Guest
Posts: n/a
 
      07-31-2006
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?

 
Reply With Quote
 
 
 
 
sarah.ali1@gmail.com
Guest
Posts: n/a
 
      07-31-2006
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

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      07-31-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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....16ebc326f0eb9a
>



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.


--
Rob

 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      07-31-2006
(E-Mail 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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Alert..General Alert?..New Discovery?. =?Utf-8?B?U3BhbW1lcipLaWxsZXI=?= Wireless Networking 0 07-24-2007 03:36 PM
on click in popup window throws alert : need to avoid alert of postdata Ganesh ASP .Net 0 06-29-2007 06:51 AM
How to create a form Alert - Not using Alert Boxes Mersh Java 0 03-13-2007 04:14 PM
Remove Windows Security Alert? its_my_dime Computer Support 1 09-17-2004 02:22 PM
ALERT: Virus Scam Alert! Toronto Garage Door Company Computer Support 1 11-18-2003 04:16 PM



Advertisments