SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    refresh the div's content

    I have a div.
    each 8 seconds i want to refresh the content of a div.
    in array eventi there are text that i want insert in div.
    I use this code:
    <div id='eventi_consigliati'></div>
    <script>
    var i=0;
    function eventiConsigliati(){
    if(++i>=eventi.length)i=0;
    document.getElementById('eventi_consigliati').innerHTML=eventi[i];
    }
    setInterval('eventiConsigliati()',8000);
    </script>

    But this not works very well
    How i can do ?
    Thanks

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You haven't posted all your code, what is eventi? Also, what does Firefox's JavaScript console tell you?

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    eventi is an array that content text.
    Ex:
    eventi=new Array("hello","bye");

    The console of firefox not show errors.
    the refresh works but no every 8 seconds.

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works fine for me here. Every 8 seconds the text will be updated. Maybe you got other scripts on the page causing the issue?

    Tip, dont pass a string to the setInterval method, pass the function itself
    Code:
    window.setInterval(eventiConsigliati, 8000);


Bookmarks

Posting Permissions

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