Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setTimeout("FuncName", 500); gets is not defined

    G'day All,
    I'm checking to see if a script has been loaded.
    I have set
    var externalScriptLoaded = true;
    in the script being loaded.
    Code:
    checkScriptLoaded;
    function checkScriptLoaded() {
    	if(!externalScriptLoaded) {
    		alert("BooHoo it's NOT loaded");
    		setTimeout("checkScriptLoaded", 500);
    	} else {
    		// script loaded and ready to use
    		alert("Hoorah it's loaded");
    	}
    }
    However I get "checkScriptLoaded is not defined"

    Can someone tell me why?

    Thanking you in anticipation,
    Htizo

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    setTimeout("checkScriptLoaded()", 500);


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #3
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Treat the first parameter like an eval().
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • #4
    New Coder
    Join Date
    Jan 2009
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    G'day,
    Thank you both for your replies.

    I tried :
    setTimeout("checkScriptLoaded()", 500);
    same message
    "checkScriptLoaded is not defined"

    Treat the first parameter like an eval().
    I'm afraid I don't understand that :-(
    (I'll do a google now.)
    Could you explain?

    Thanks,
    Htizo
    Last edited by htizo; 01-18-2009 at 09:21 PM. Reason: typo

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    setTimeout("checkScriptLoaded()", 500);

  • #6
    New Coder
    Join Date
    Jan 2009
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    G'day Philip,

    Sorry mate typo, I did try:
    setTimeout("checkScriptLoaded()", 500);
    this time i copied from the editor.

    Thanks for taking the time to reply!
    Any other ideas?

    Thanks and sorry mate,
    Htizo

  • #7
    Regular Coder
    Join Date
    Mar 2007
    Posts
    357
    Thanks
    46
    Thanked 22 Times in 21 Posts
    Could it maybe be that you're calling it without any parenthesis? Errors in red:

    Code:
    checkScriptLoaded;
    function checkScriptLoaded() {
    	if(!externalScriptLoaded) {
    		alert("BooHoo it's NOT loaded");
    		setTimeout("checkScriptLoaded", 500);
    	} else {
    		// script loaded and ready to use
    		alert("Hoorah it's loaded");
    	}
    }
    Fixed:
    Code:
    checkScriptLoaded();
    function checkScriptLoaded() {
    	if(!externalScriptLoaded) {
    		alert("BooHoo it's NOT loaded");
    		setTimeout("checkScriptLoaded()", 500);
    	} else {
    		// script loaded and ready to use
    		alert("Hoorah it's loaded");
    	}
    }
    For the record, you can actually do this in setTimeout

    Code:
    setTimeout( checkScriptLoaded, 500 )
    This works because you aren't calling checkScriptLoaded, you are passing the signature of the function. It's very slightly more efficient to pass the function signature like this because passing it as a string means the function has to parse the string to match the function. Only time you need to use a string would be if you want to pass an argument through it, like "checkScriptLoaded( argument1, argument 2 )".

    Hope that helps.

  • #8
    New Coder
    Join Date
    Jan 2009
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by flynch01 View Post
    For the record, you can actually do this in setTimeout
    Code:
    setTimeout( checkScriptLoaded, 500 )
    This works because you aren't calling checkScriptLoaded, you are passing the signature of the function. It's very slightly more efficient to pass the function signature like this because passing it as a string means the function has to parse the string to match the function. Only time you need to use a string would be if you want to pass an argument through it, like "checkScriptLoaded( argument1, argument 2 )".

    Hope that helps.
    It does !
    I tried all the others above and they give the same error however when I removed the quotes it works.
    THANK YOU.

    However the variable set true in the script being loaded is not returning true.
    More work to do :-)

    Thanks to all who replied,
    Htizo

  • #9
    New Coder
    Join Date
    Jan 2009
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    G'day All,
    Thanks to all but particularly flynch01 as I now have a working script.
    This is what worked. The fail safe is important!

    Code:
    //In the script I'm loading, sb.js I set the variable "var externalScriptLoaded = true;"
    //for some reason I need to set the variable false on this page.
    externalScriptLoaded = false;
    //var externalScriptLoaded = false; //DOES NOT WORK, WHY ????
    var counti = 1;//we need a fail safe.
    
    checkScriptLoaded();//call the function.
    
    function checkScriptLoaded() {
    	if(!externalScriptLoaded) {
    		alertMe("BooHoo it's NOT loaded");
    		counti++;//increment counter
    		if (counti != 10){ //is 5 seconds enough?
    			setTimeout( checkScriptLoaded, 500 );//run this script every half second
    		}else{
    			alertMe("The script failed to load");
    		}
    	} else {
    		// script loaded and ready to use
    		alertMe("Hoorah it's loaded");
    		initRunSB();//function to run the script
    		//return true;
    	}
    }
    Again, Thanks to all!
    Htizo

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by htizo View Post
    //var externalScriptLoaded = false; //DOES NOT WORK, WHY ????
    Because if the variable externalScriptLoaded is declared within a function in the sb.js file the var prefix makes the variable local to that function only.


    A child of five would understand this. Send someone to fetch a child of five. - Groucho Marx

  • #11
    New Coder
    Join Date
    Jan 2009
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Phil.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •