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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    410
    Thanks
    6
    Thanked 3 Times in 3 Posts

    JS variable is not advancing to 10 ?

    I have no problem with the code as far as is function goes, but when I added the latest entry to the list it never shows this entry on my page. It only goes to number 9 and does not go to quote[10]. Can anyone see what might be causing this ?

    This is my JS code
    Code:
    <script type="text/javascript">
    
    var moving = "http://www.site.com";
    
    var quote = new Array();
    quote[0] = "<div class=\"quoteText\">0</div><span class=\"quoteName\">Kate</span> <span class=\"quoteDate\">(17-06-2011)</span><br><span class=\"quoteLink\"><a href=\"" + moving + "\" target=\"_blank\">View origin of quote</a></span>";
    quote[1] = "<div class=\"quoteText\">1</div><span class=\"quoteName\">Fi</span> <span class=\"quoteDate\">(11-08-2011)</span><br><span class=\"quoteLink\"><a href=\"" + moving + "\" target=\"_blank\">View origin of quote</a></span>";
    quote[2] = "<div class=\"quoteText\">2</div><span class=\"quoteName\">salome</span> <span class=\"quoteDate\">(30-08-2011)</span><br><span class=\"quoteLink\"><a href=\"" + moving + "\" target=\"_blank\">View origin of quote</a></span>";
    quote[3] = "<div class=\"quoteText\">3</div><span class=\"quoteName\">kobi</span> <span class=\"quoteDate\">(09-09-2011)</span><br><span class=\"quoteLink\"><a href=\"" + moving + "\" target=\"_blank\">View origin of quote</a></span>";
    quote[4] = "<div class=\"quoteText\">4</div><span class=\"quoteName\">Annie</span> <span class=\"quoteDate\">(07-02-2012)</span><br><span class=\"quoteLink\"><a href=\"" + moving + "\" target=\"_blank\">View origin of quote</a></span>";
    quote[5] = "<div class=\"quoteText\">5</div><span class=\"quoteName\">Claire</span> <span class=\"quoteDate\">(02-04-2012)</span><br><span class=\"quoteLink\"><a href=\"" + moving + "\" target=\"_blank\">View origin of quote</a></span>";
    
    
    
    
    
    quote[6] = "<div class=\"quoteText\">6</div><span class=\"quoteName\">Nish and Jesmin</span> <span class=\"quoteDate\">(14-07-2012)</span><br>"; // from own site.
    quote[7] = "<div class=\"quoteText\">7</div><span class=\"quoteName\">Mel</span> <span class=\"quoteDate\">(12-08-2012)</span><br>"; // from own site.
    quote[8] = "<div class=\"quoteText\">8</div><span class=\"quoteName\">Melanie</span> <span class=\"quoteDate\">(03-08-2012)</span><br>"; // from own site.
    quote[9] = "<div class=\"quoteText\">9</div><span class=\"quoteName\">Richard</span> <span class=\"quoteDate\">(25-08-2012)</span><br>"; // from own site.
    
    
    
    quote[10] = "<div class=\"quoteText\">10</div><span class=\"quoteName\">Liz</span> <span class=\"quoteDate\">(20-07-2011)</span><br>"; // from own site.
    
    
    
    
    //quote[11] = "";
    //quote[12] = "";
    //quote[13] = "";
    //quote[14] = "";
    //quote[15] = "";
    //quote[16] = "";
    //quote[17] = "";
    //quote[18] = "";
    //quote[19] = "";
    //quote[20] = "END";
    
    
    var qno = 0;
    var timer;
    var run=true;
    //*********************************
    // Add a message to the DIV 
    //*********************************
    function addMsg() 
    {
    		if (run===true) {
    					obj = document.getElementById('divQuote');
    					//txt = document.createTextNode(quote[qno]);
    					//obj.appendChild(txt);
    					obj.innerHTML += quote[qno];
    					obj.appendChild(document.createElement('hr'));
    					qno++;
    					if (qno == quote.length-1)
    					{
    						qno = 0;	//clearInterval(timer); //clear the timer if all the quotes are done!
    					}
    					//Apply Scroll
    					var currentScrollHeight = obj.scrollHeight;
    					if (currentScrollHeight >= parseInt(obj.style.height)) // check if the scroll bar is visible now.
    					{
    						obj.scrollTop=(obj.scrollTop +100); //set the scroll height to scroll by here. (currently set to 100)
    					}
    		}
    }
    
    
    //*********************************************
    // Start a timer to add the messages on load.
    //*********************************************
    function populate() 
    {
    	timer = setInterval('addMsg()', 2000); // start an interval timer.
    }
    
    </script>

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    if (qno == quote.length-1)

    Quote 0 through 10 has a length of 11. 11-1=10, so when it gets to the tenth quote, it resets to 0.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".


  •  

    Posting Permissions

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