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 to the CF scene
    Join Date
    Jan 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error when refreshing page

    hey guys!

    this looks like a cool forum! ok, i wrote a little script that will flip through random quotes and display them in a table every few seconds. problem is the first time the page is loaded it give an error. also, when i refresh the page, the code gives an error.

    here is the code:
    Code:
    var CurrentMsg;//-> had original message in here
    
    function update(msg)
    {
    	CurrentMsg = msg;                           
    	document.getElementById("customerQuote").innerHTML=CurrentMsg;
    	clearTimeout(timer);                           
    	timer = setTimeout("idleMsg()",6500);        
    }
    function update2(msg)
    {
    	CurrentMsg = msg;                           
    	document.getElementById("custName").innerHTML=CurrentMsg;
    	clearTimeout(timer);                           
    	timer = setTimeout("idleMsg()",6500);    
    }
    
    var notice_num = 4; // -> change this to length of array  
           
    var notices = new Array();
    notices[1] = 'We\'ve used Superior Snow Remov...excellent.';
    notices[2] = '"I need my shopping center cleared ..."';
    notices[3] = '"We\'ve used Superior for 4 years now and they\'re an excellent service. ...."';        
    notices[4] = '"Superior does an excellent job handling ..."';                   
    
    var customers = new Array();
    customers[1] = "Alvin Trumbone<br> Aldi Inc. <br> #54, 46th & Market Philadelphia, PA.";
    customers[2] = "Frank Ullman<br> Brentway Management LLC ";
    customers[3] = "Barbara Corvo<br> Dion-Segal Associates";
    customers[4] = "Barbara Claffie<br> Stein Investment Group";	
    
    var timer = setTimeout('idleMsg()',0); // time before first message appears                            
    
    function idleMsg()
    {  
    
    	index = 1 + Math.round((notice_num * Math.random()));                     
    	if(index>notice_num)
    	{ 
    		index=notice_num; 
    	}
    	if(index<1)
    	{ 
    		index=1; 
    	} 
    	update(notices[index]);
    	update2(customers[index]); 
    }
    any ideas why this is buggy?? I've been testing in IE 6 on winXP

    thanks for reading this post,
    IPfreely

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Look at this line and count the quote marks:

    Code:
    notices[1] = 'We've used Superior Snow Remov...excellent.';
    You've got to remember to escape those embedded quotes so they don't prematurely terminate your string.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey roy!

    thank you for looking - in my code those are actually escaped i guess when posting in a forum those slashes are stripped out or something. After more investigation I now see the error is:

    Error:'document.getElementById(...)' is null or not an object

    what does that mean?


    thanks,
    IPfreely

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    It means that it does not find an element with the id you send to that function in the document tree.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm odd.. i labeled the spans respectively: id="customerQuote" and id="custName" and it works sometimes.

    Is there a difference between using document.getElementById and document.getElementByName??
    arg this is frustrating!

    thank you,
    IPfreely

  • #6
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Don't even think of using getElementsByName - it's the single DOM1 functionality that does not work as it should in ANY browser. All of them are buggy in their own particular way, of course.

    No, that is not likely to be the problem. First, check the case of the ids again. If it matches, your problem is likely one of timing. The DOM functions must be used after the document has been loaded, they do not work while loading.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #7
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    nuts i think you are right - i don't know how to make sure that script loads after the page loads. if you look at the script you'll see that:

    var timer = setTimeout('idleMsg()',0);

    is what sets everything going and i'm not sure how to make sure the page loads before calling that line

    thanks guys,

    IPfreely

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just move that line to a point just before the </body> tag on your page. That'll probably require it's own <script></script> tags but it'll also make sure that everything the script references will be in existance by then.

    I would also increase that number from 0 to something like 1000 since the zero value there means run it right away which makes calling using setTimeout a waste, 1000 would cause it to wait one second (1000 milliseconds).
    Last edited by Roy Sinclair; 01-07-2004 at 05:29 PM.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #9
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    The best solution would be to use the onload event to set the timeout, if you at all need the timeout.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #10
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow i'm a moron - i'm going to try that
    - let you know


    thanks!
    IPfreely

  • #11
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    damn tried it a hundred ways and won't work - i think i'm going to redo this all in flash

    thanks for your help !!
    IPfreely


  •  

    Posting Permissions

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