Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Refresh Div content

Refresh Div content

Scheduled Pinned Locked Moved JavaScript
c++javahtmlhelp
4 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shantanu Gupta 1337
    wrote on last edited by
    #1

    I am making a school project based on jsp, i have a page in the solution which shows an animated Redirecting using following code var ic = 0; var s0 = "Redirecting"; var s1 = "Redirecting."; var s2 = "Redirecting.."; var s3 = "Redirecting..."; function redir() { ic++; switch(ic) { case 1: $('#text').html(s0); break; case 2: $('#text').html(s1); break; case 3: $('#text').html(s2); break; case 4: $('#text').html(s3); ic = 0; break; default: $('#text').html(s0); ic = 0; } setTimeout(redir(), 500); return 0; } Problem is the div does not refresh (shows only "Redirecting." without any change) periodically with the text change calls. Thanks in advance

    D 1 Reply Last reply
    0
    • S Shantanu Gupta 1337

      I am making a school project based on jsp, i have a page in the solution which shows an animated Redirecting using following code var ic = 0; var s0 = "Redirecting"; var s1 = "Redirecting."; var s2 = "Redirecting.."; var s3 = "Redirecting..."; function redir() { ic++; switch(ic) { case 1: $('#text').html(s0); break; case 2: $('#text').html(s1); break; case 3: $('#text').html(s2); break; case 4: $('#text').html(s3); ic = 0; break; default: $('#text').html(s0); ic = 0; } setTimeout(redir(), 500); return 0; } Problem is the div does not refresh (shows only "Redirecting." without any change) periodically with the text change calls. Thanks in advance

      D Offline
      D Offline
      daveyerwin
      wrote on last edited by
      #2

      <!DOCTYPE html>
      <html>
      <head>
      <script src="http://code.jquery.com/jquery-latest.min.js"></script>
      <script>
      var ic = 0;
      var s0 = "Redirecting";
      var s1 = "Redirecting.";
      var s2 = "Redirecting..";
      var s3 = "Redirecting...";
      function redir(ic) {
      ic++;
      switch(ic) {
      case 1:
      $('#text1').html(s0);
      break;
      case 2:
      $('#text1').html(s1);
      break;
      case 3:
      $('#text1').html(s2);
      break;
      case 4:
      $('#text1').html(s3);
      ic = 0;
      break;
      default:
      $('#text1').html(s0);
      }
      if(ic > 0){setTimeout("redir("+ic+")", 500);}
      return 0;
      }
      </script>
      </head>
      <body>
      <div id="text1"></div>
      <script>
      redir(ic);
      </script>
      </body>
      </html>

      This works but you really should change the code to use use setInterval instead of setTimeout

      modified on Saturday, July 31, 2010 2:01 PM

      S 1 Reply Last reply
      0
      • D daveyerwin

        <!DOCTYPE html>
        <html>
        <head>
        <script src="http://code.jquery.com/jquery-latest.min.js"></script>
        <script>
        var ic = 0;
        var s0 = "Redirecting";
        var s1 = "Redirecting.";
        var s2 = "Redirecting..";
        var s3 = "Redirecting...";
        function redir(ic) {
        ic++;
        switch(ic) {
        case 1:
        $('#text1').html(s0);
        break;
        case 2:
        $('#text1').html(s1);
        break;
        case 3:
        $('#text1').html(s2);
        break;
        case 4:
        $('#text1').html(s3);
        ic = 0;
        break;
        default:
        $('#text1').html(s0);
        }
        if(ic > 0){setTimeout("redir("+ic+")", 500);}
        return 0;
        }
        </script>
        </head>
        <body>
        <div id="text1"></div>
        <script>
        redir(ic);
        </script>
        </body>
        </html>

        This works but you really should change the code to use use setInterval instead of setTimeout

        modified on Saturday, July 31, 2010 2:01 PM

        S Offline
        S Offline
        Shantanu Gupta 1337
        wrote on last edited by
        #3

        well thanks mate, cheers but i have edited your code a bit to just meet that edge:function redir(ic) { ic++; switch(ic) { case 1: $('#text1').text(s0); break; case 2: $('#text1').text(s1); break; case 3: $('#text1').text(s2); break; case 4: $('#text1').text(s3); ic = 0; break; default: $('#text1').text(s0); } setInterval("redir("+ic+")", 500); return 0; } </script>

        D 1 Reply Last reply
        0
        • S Shantanu Gupta 1337

          well thanks mate, cheers but i have edited your code a bit to just meet that edge:function redir(ic) { ic++; switch(ic) { case 1: $('#text1').text(s0); break; case 2: $('#text1').text(s1); break; case 3: $('#text1').text(s2); break; case 4: $('#text1').text(s3); ic = 0; break; default: $('#text1').text(s0); } setInterval("redir("+ic+")", 500); return 0; } </script>

          D Offline
          D Offline
          daveyerwin
          wrote on last edited by
          #4

          Shantanu Gupta 1337 wrote:

          but i have edited your code a bit to just meet that edge:

          You have edited your own code which I had modified. If it were my code it would look like this ...

          <html>
          <head>
          <script src="http://code.jquery.com/jquery-latest.min.js"></script>
          <script>
          var redir = (function(){
          this.ic = 0;
          this.ar = arguments;
          return function(){
          if(++ic == ar.length){ic = 1;};
          $('#'+ar[0]).html(ar[ic])};})
          ("text1","Redirecting","Redirecting.","Redirecting..","Redirecting...")
          </script>
          </head>
          <body>
          <div id="text1"></div>
          </body>
          <script>
          setInterval(redir,500);
          </script>
          </html>

          modified on Sunday, August 1, 2010 4:40 PM

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups